/[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 by dpavlin, Fri May 12 12:01:08 2000 UTC revision 1.13 by dpavlin, Wed Sep 6 10:49:15 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            show last lock date
70            
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 91  function StartHTML($title,$text="") { Line 157  function StartHTML($title,$text="") {
157    
158  <HTML>  <HTML>
159  <HEAD>  <HEAD>
160   <TITLE><?php echo $host . " " . $title ?></TITLE>   <TITLE><?= $host . " " . $title ?></TITLE>
161   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">
162   <META NAME="keywords" CONTENT="site manager, web site maintenance">   <META NAME="keywords" CONTENT="site manager, web site maintenance">
163   <META NAME="robots" CONTENT="noindex">   <META NAME="robots" CONTENT="noindex">
164   <META HTTP-EQUIV="expires" CONTENT="0">   <META HTTP-EQUIV="expires" CONTENT="0">
165   <LINK REL="stylesheet" TYPE="text/css"   <LINK REL="stylesheet" TYPE="text/css"
166          HREF="<?php echo $self ?>?STYLE=get">          HREF="<?= $self ?>?STYLE=get">
167  </HEAD>  </HEAD>
168  <BODY BGCOLOR="#FFFFFF">  <BODY BGCOLOR="#FFFFFF">
169   <H3 ALIGN="RIGHT"><?php echo $host ?></H3>   <H3 ALIGN="RIGHT"><?= $host ?></H3>
170  <TABLE BORDER=0 WIDTH="100%"><TR>  <TABLE BORDER=0 WIDTH="100%"><TR>
171   <TD CLASS=INV><?php echo $title ?></TD></TR></TABLE>   <TD CLASS=INV><?= $title ?></TD></TR></TABLE>
172   <P><?php echo $text ?></P>   <P><?= $text ?></P>
173    
174  <?php  <?php
175  } // end function StartHTML  } // end function StartHTML
# 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="<?= $GLOBALS["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            $file_lock = CheckLock($fsPath);
244    
245          if (!$editable && !$exists)          if (!$editable && !$exists)
246                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
247          if (!exists && !Writeable($fsDir) )          if (!exists && !is_writeable($fsDir) )
248                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
249    
250          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
# Line 179  function DetailPage($fsRoot,$relDir,$fn) Line 255  function DetailPage($fsRoot,$relDir,$fn)
255    
256          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;
257          if ($exists) {  // get file info          if ($exists) {  // get file info
258            $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
259            $fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
260            $faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
261            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;
262            echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
263            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
264            echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;
265            echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;
266            echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
267            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
268            echo "</PRE>" ;                  echo "</PRE>" ;
269    
270          }          }
271    
272          if ( $editable && ($writable || !$exists) ) {          if ( $editable && ($writable || !$exists) && !$file_lock ) {
273                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
274                  rewind($fh) ;                  rewind($fh) ;
275                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 200  function DetailPage($fsRoot,$relDir,$fn) Line 277  function DetailPage($fsRoot,$relDir,$fn)
277                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
278  ?>  ?>
279    
280  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
281  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
282          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
283  </SPAN><BR>  </SPAN><BR>
284  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
285  echo($fstr) ; ?></TEXTAREA>  echo($fstr) ; ?></TEXTAREA>
286  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
287  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
288  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
289  <INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
290          VALUE="<?php echo $relPath ; ?>">          VALUE="<?= $relPath ; ?>">
291  <INPUT TYPE="RESET" VALUE="RESET">  <br>
292    <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
293  <INPUT TYPE="SUBMIT" VALUE="SAVE">  <INPUT TYPE="SUBMIT" VALUE="SAVE">
294  </FORM>  </FORM>
295    
296  <?php  <?php
297          }          }
298          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && strstr(join(" ",$gblImages),$ext) ) {  
299            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
300            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
301            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
302            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
303            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
304                    echo $tstr ;
305          }          }
306    
307  ?>  ?>
308    
309  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
310  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
311  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
312  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
313    
314  <?php  <?php
315    
316            if ($file_lock) {
317    ?>
318    <hr>
319    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
320    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
321    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
322    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
323    <?
324            } // file_lock
325    
326            if (substr($fn,0,4) == ".del") {
327                    $action="UNDELETE";
328                    $desc="undelete previously deleted file";
329            } else {
330                    $action="DELETE";
331                    $desc="delete";
332            }
333    
334          if ($exists && $writable) {          if ($exists && $writable) {
335  ?>  ?>
336    
337  <HR><SPAN TITLE="Check OK and click [DELETE] to delete.">  <HR>
338  <B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN>  <a name="undelete">
339    <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
340    <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>
341  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
342  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
343    
344    <HR>
345    <a name="rename">
346    <SPAN TITLE="Check OK and click [RENAME] to rename.">
347    <B>OK TO RENAME "<?= $fn ; ?>" TO
348    <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
349    ? </B></SPAN>
350    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
351    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
352    
353    <?php
354            }       // exists && writable
355    ?>
356    <HR>
357    <a name="note">
358    <B>NOTE FOR "<?= $fn ; ?>":
359    <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">
360    </B></SPAN>
361    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
362    
363    </FORM>
364    
365  <?php  <?php
366            
367            $name=basename("$fsDir/$fn");
368            $logname=dirname("$fsDir/$fn")."/.log/$name";
369            $bakdir=dirname("$fsDir/$fn")."/.bak";
370            if (file_exists($logname)) {
371                    $log=fopen($logname,"r");
372                    $cl1=" class=lst"; $cl2="";
373                    $logarr = array();
374                    while($line = fgetcsv($log,255,"\t")) {
375                            $cl=$cl1; $cl1=$cl2; $cl2=$cl;
376                            array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
377                    }
378                    fclose($log);
379                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
380                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
381                    while ($e = array_shift($logarr)) {
382                            if (strstr($e[4],"upload")) {
383                                    if (file_exists("$bakdir/$bakcount/$name")) {
384                                            $e[4]="<a href=\"".dirname($relPath)."/.bak/$bakcount/$name\">$e[4]</a>";
385                                    }
386                                    $bakcount++;
387                            }
388                            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";
389                    }
390                    print "</table>";
391          }          }
392          echo "</FORM>" ;  
393          EndHTML() ;          EndHTML() ;
394    
395  } // end function DetailPage  } // end function DetailPage
# Line 472  function GifIcon($txt) { Line 619  function GifIcon($txt) {
619          case "blank" :          case "blank" :
620                  $d = "blank.gif" ;                  $d = "blank.gif" ;
621                  break ;                  break ;
622            case "checkout":
623                    $d = "box2.gif";
624                    break;
625            case "checkin":
626                    $d = "hand.up.gif";
627                    break;
628            case "locked":
629                    $d = "screw2.gif";
630                    break;
631            case "note":
632                    $d = "quill.gif";
633                    break;
634          default :          default :
635                  $d = "generic.gif" ;                  $d = "generic.gif" ;
636          }          }
# Line 486  function Navigate($fsRoot,$relDir) { Line 645  function Navigate($fsRoot,$relDir) {
645          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon ;
646    
647          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
648          $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
649                    $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;
650            } else {
651                    $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;
652            }
653          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir    = $fsRoot . $relDir . "/" ; // current directory
654    
655          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 658  function Navigate($fsRoot,$relDir) {
658          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
659                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
660          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
661                  if ( $item == ".." || $item == "." ) continue ;                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;
662                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
663                          $dirList[] = $item ;                          $dirList[] = $item ;
664                  }                  } else if ( is_file($fsDir . $item) ) {
                 else if ( is_file($fsDir . $item) ) {  
665                          $fileList[] = $item ;                                    $fileList[] = $item ;          
666                  }                  } else if ( is_link($fsDir . $item) ) {
667                  else {                          $dirList[] = $item ;
668                    } else {
669                    // unknown file type                    // unknown file type
670                    // $text = "Could not determine file type of " ;                    // $text = "Could not determine file type of " ;
671                    // Error("File Error", $text.$relDir."/".$item) ;                    // Error("File Error", $text.$relDir."/".$item) ;
# Line 510  function Navigate($fsRoot,$relDir) { Line 673  function Navigate($fsRoot,$relDir) {
673                  }                  }
674          }          }
675          closedir($dir) ;          closedir($dir) ;
676    
677            // scan deleted files
678            if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
679                    while ($item = readdir($dir)) {
680                            if ( substr($item,0,1) == "." ) continue ;
681                            $fileList[] = ".del/$item" ;            
682                    }
683                    closedir($dir) ;
684            }
685    
686          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
687    
688          // start navigation page          // start navigation page
689          $text  = "Use this page to add, delete or " ;          $text  = "Use this page to add, delete";
690          $text .= "revise files on this web site." ;          if (! isset($show_deleted)) {
691                    $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
692            }
693            $text .= " or revise files on this web site." ;
694          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
695    
696          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 527  function Navigate($fsRoot,$relDir) { Line 702  function Navigate($fsRoot,$relDir) {
702                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
703  ?>  ?>
704    
705  <TR><TD><?php echo $gblIcon("up") ?></TD><TD COLSPAN=4 CLASS=LST>  <TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST>
706  <A HREF="<?php echo $self ?>?D=<?php echo urlencode($parent) ?>">  <A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>">
707  <B><?php echo $parent ?></B></A></TD></TR>  <B><?= $parent ?></B></A></TD></TR>
708    
709  <?php  <?php
710          }          }
# Line 539  function Navigate($fsRoot,$relDir) { Line 714  function Navigate($fsRoot,$relDir) {
714                  sort($dirList) ;                  sort($dirList) ;
715  ?>  ?>
716    
717  <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>
718    
719  <?php  <?php
720                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
# Line 549  function Navigate($fsRoot,$relDir) { Line 724  function Navigate($fsRoot,$relDir) {
724                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
725  ?>  ?>
726    
727  <TR><TD><?php echo $gblIcon("fldr") ?></TD>  <TR><TD><?= $gblIcon("fldr") ?></TD>
728  <TD COLSPAN=4 CLASS=LST><?php echo $tstr ?></TD></TR>  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>
729    
730  <?php  <?php
731                  }  // iterate over dirs                  }  // iterate over dirs
732          }  // end if no dirs          }  // end if no dirs
733  ?>  ?>
734    
735  <TR><TD></TD><TD COLSPAN=4><HR><B><?php echo $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
736  </B></TD></TR>  </B></TD></TR>
737  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
738  <TD><?php echo $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
739    <TD CLASS=TOP>NOTE</TD>
740  <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>
741    
742  <?php  <?php
743          if (sizeof($fileList) > 0) {          if (sizeof($fileList) > 0) {
744            sort($fileList) ;            sort($fileList) ;
745            while (list($key,$file) = each($fileList)) {              while (list($key,$file) = each($fileList)) {  
746              $path = $fsDir."/".$file ;                  $path = $fsDir."/".$file ;
747              $mod  = filemtime($path) ;                  $mod  = filemtime($path) ;
748              $sz   = filesize($path) ;                  $sz   = filesize($path) ;
749    
750              if ($sz >= 10240) {                  if ($sz >= 10240) {
751                $sz = (int)(($sz+1023)/1024) . " k" ;                          $sz = (int)(($sz+1023)/1024) . " k" ;
752              }                  } else {
753              else {                          $sz .= " " ;
754                $sz .= " " ;                  } // end size
755              } // end size  
756                    $a = $b = "" ;
757              $a = $b = "" ;  
758                    $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
759              if ( ($mod + 30*86400) > time() ) {  
760                $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                  if ( ($mod + 30*86400) > time() ) {
761                $a .= " than 30 days\"> * </SPAN>" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
762              }                          $a .= " than 30 days\"> * </SPAN>" ;
763                    }
764              $tstr = $webRoot . $relDir . "/" . $file ;  
765              $tstr  = "<A HREF=\"" . $tstr . "\">" ;                  $file_lock=CheckLock($path);
766              $tstr .= $file . "</A>" . $a ;  
767                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
768              $ext = strtolower(strrchr($file,".")) ;                  $file_url_html.="&D=".urlencode($relDir);
769              if ( $ext=="" ||                  $file_url_html.="\" TITLE=\"View file\">" ;
770                   strstr(join(" ",$gblEditable),$ext) )  
771              {                    if (substr($file,0,5) != ".del/") {
772                $b  = "<A HREF=\"" . $self . "?A=C&F=" ;                          $file_url_html .= $file . "</A>" . $a ;
773                $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                  } else {
774                $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>";
775                $b .= $gblIcon("view") . "</A>" ;                  }
776              }  
777                    $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
778    
779                    $ext = strtolower(strrchr($file,".")) ;
780    
781                    if ($file_lock) {
782                            if ($file_lock == $GLOBALS[gblUserName]) {
783                                    $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
784                                    $b.="&D=".urlencode($relDir);
785                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
786                                    $file_url_html=$b;
787                                    $b.=$gblIcon("checkin")."</A>" ;
788                                    $b.= $gblIcon("blank");
789                                    $file_url_html.="$file</a> $a";
790                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
791                            } else {
792                                    $b = $gblIcon("locked");
793                                    $b.= $gblIcon("blank");
794                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
795                                    $file_url_html = "$file $a";
796                            }
797                    } else {
798                            $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
799                            $b.="&D=".urlencode($relDir);
800                            $b.="\" TITLE=\"Checkout file for edit\">" ;
801                            $b.=$gblIcon("checkout")."</A>" ;
802    
803                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
804                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
805                                    $b.="&D=".urlencode($relDir);
806                                    $b.="\" TITLE=\"List contents\">" ;
807                                    $b.=$gblIcon("view")."</A>" ;
808                            } else {
809                                    $b.= $gblIcon("blank");
810                            }
811                    }
812    
813    
814  ?>  ?>
815    
816  <TR><TD>  <TR><TD>
817  <A HREF="<?php echo $self ?>?A=E&F=<?php echo urlencode($file)  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
818  ?>&D=<?php echo urlencode($relDir) ?>" TITLE="View/Edit">  <?= $gblIcon($ext) ?></A></TD>
819  <?php echo $gblIcon($ext) ?></A></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
820  <TD CLASS=LST><?php echo $tstr ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
821  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
822  <TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
823  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
824    
825  <?php  <?php
826            }  // iterate over files            }  // iterate over files
# Line 617  function Navigate($fsRoot,$relDir) { Line 829  function Navigate($fsRoot,$relDir) {
829          if ($emptyDir) {          if ($emptyDir) {
830  ?>  ?>
831    
832  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
833   <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>   <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
834    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
835    OK TO DELETE THIS EMPTY FOLDER?    OK TO DELETE THIS EMPTY FOLDER?
836    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
837    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
# Line 630  function Navigate($fsRoot,$relDir) { Line 842  function Navigate($fsRoot,$relDir) {
842          } // end if emptyDir          } // end if emptyDir
843  ?>  ?>
844    
845  <TR><TD></TD><TD COLSPAN=4><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
846    
847  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <TR><TD></TD><TD COLSPAN=5>
848  <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>CREATE NEW  <?
849    if (file_exists(".info.inc")) {
850            include(".info.inc");
851    }
852    ?>
853    </TD></TR>
854    
855    <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
856    
857    <FORM METHOD="POST" ACTION="<?= $self ?>">
858    <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
859   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
860   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
861   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
862   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
863   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
864   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
865   <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  
866   </NOBR>   </NOBR>
867  </TD></TR>  </TD></TR>
868  </FORM>  </FORM>
# Line 653  function Navigate($fsRoot,$relDir) { Line 874  function Navigate($fsRoot,$relDir) {
874    
875  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
876    
877  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename) {
878    
879          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
880          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 661  function UploadPage($fsRoot, $relDir) { Line 882  function UploadPage($fsRoot, $relDir) {
882    
883  <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>
884  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
885   ACTION="<?php echo $self ?>">   ACTION="<?= $self ?>">
886  DESTINATION DIRECTORY:<B><?php echo " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
887    <? if (isset($filename)) { ?>
888    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
889    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
890    <? } ?>
891  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
892  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
893  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
894  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
895  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
896  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
897  you must upgrade to an RFC1867-compliant browser.</P>  you must upgrade to an RFC1867-compliant browser.</P>
898  <P>Your browser:<BR><?php echo $GLOBALS["HTTP_USER_AGENT"] ?></P>  <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
899  </FORM>  </FORM>
900  </TD></TR>  </TD></TR>
901  <TR><TD></TD><TD>  <TR><TD></TD><TD>
902  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
903  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>"><BR>  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
904  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
905  </FORM>  </FORM>
906  </TD></TR></TABLE></P>  </TD></TR></TABLE></P>
# Line 694  function Error($title,$text="") { Line 919  function Error($title,$text="") {
919    
920  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
921    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
922  function CreateHash($user, $pw) {  function CreateHash($user, $pw) {
923    
924          global $gblHash ;  // hash function to use          global $gblHash ;  // hash function to use
# Line 749  function NoEntry() { Line 953  function NoEntry() {
953          StartHTML($title,$text) ;          StartHTML($title,$text) ;
954  ?>  ?>
955    
956  <FORM ACTION="<?php echo $self ?>?HASH=create" METHOD="POST">  <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">
957  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?php echo $user ?>">  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">
958  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?php echo $pw ?>">  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $pw ?>">
959    
960  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>
961  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 971  the source<BR>of this file.<BR><BR>
971    
972  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
973    
974    function Logit($target,$msg) {
975    
976            $dir=dirname($target);
977            if (! file_exists($dir."/.log")) {
978                    mkdir($dir."/.log",0700);
979            }
980            $file=basename($target);
981    
982            $log=fopen("$dir/.log/$file","a+");
983            fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
984                    "\t$GLOBALS[gblUserName]\t$msg\n");
985            fclose($log);
986    
987    }
988    
989    
990    //////////////////////////////////////////////////////////////////
991    
992    function WriteNote($target,$msg) {
993    
994            $dir=dirname($target);
995            if (! file_exists($dir."/.note")) {
996                    mkdir($dir."/.note",0700);
997            }
998            $file=basename($target);
999    
1000            $note=fopen("$dir/.note/$file","w");
1001            fputs($note,"$msg\n");
1002            fclose($note);
1003    
1004            Logit($target,"added note $msg");
1005    
1006    }
1007    
1008    function ReadNote($target) {
1009    
1010            $dir=dirname($target);
1011            $file=basename($target);
1012            $msg="";
1013            if (file_exists($dir."/.note/$file")) {
1014                    $note=fopen("$dir/.note/$file","r");
1015                    $msg=fgets($note,4096);
1016                    fclose($note);
1017            }
1018            return StripSlashes($msg);
1019    
1020    }
1021    
1022    //////////////////////////////////////////////////////////////////
1023    
1024    function MoveTo($source,$folder) {
1025    
1026            $file=basename($source);
1027            if (! file_exists($folder)) {
1028                    mkdir($folder,0700);
1029            }
1030            if (file_exists($source)) {
1031                    rename($source,"$folder/$file");
1032            }
1033    }
1034    
1035    //////////////////////////////////////////////////////////////////
1036    
1037    function Lock($target) {
1038    
1039            $dir=dirname($target);
1040            if (! file_exists($dir."/.lock")) {
1041                    mkdir($dir."/.lock",0700);
1042            }
1043            $file=basename($target);
1044    
1045            if (file_exists("$dir/.lock/$file")) {
1046                    Logit($target,"attempt to locked allready locked file!");
1047            } else {
1048                    $lock=fopen("$dir/.lock/$file","w");
1049                    fputs($lock,"$GLOBALS[gblUserName]\n");
1050                    fclose($lock);
1051    
1052                    Logit($target,"file locked");
1053            }
1054    
1055    }
1056    
1057    function CheckLock($target) {
1058    
1059            $dir=dirname($target);
1060            $file=basename($target);
1061            $msg=0;
1062            if (file_exists($dir."/.lock/$file")) {
1063                    $lock=fopen("$dir/.lock/$file","r");
1064                    $msg=fgets($lock,4096);
1065                    fclose($lock);
1066            }
1067            return chop($msg);
1068    
1069    }
1070    
1071    function Unlock($target) {
1072    
1073            $dir=dirname($target);
1074            $file=basename($target);
1075            if (file_exists($dir."/.lock/$file")) {
1076                    unlink("$dir/.lock/$file");
1077                    Logit($target,"file unlocked");
1078            } else {
1079                    Logit($target,"attempt to unlocked non-locked file!");
1080            }
1081    
1082    }
1083    
1084    //////////////////////////////////////////////////////////////////
1085    
1086    function urlpath($url) {
1087            $url=urlencode(StripSlashes("$url"));
1088            $url=str_replace("%2F","/",$url);
1089            $url=str_replace("+","%20",$url);
1090            return($url);
1091    }
1092    
1093    //////////////////////////////////////////////////////////////////
1094    
1095    function safe_rename($from,$to) {
1096            if (file_exists($from) && is_writable(dirname($to))) {
1097                    rename($from,$to);
1098            }
1099    }
1100    
1101    //////////////////////////////////////////////////////////////////
1102    
1103  // MAIN PROGRAM  // MAIN PROGRAM
1104  // ============  // ============
1105  // query parameters: capital letters  // query parameters: capital letters
1106  // local functions : begin with capital letters  // local functions : begin with capital letters
1107  // global constants: begin with gbl  // global constants: begin with gbl
1108    
1109          $gblFilePerms = "644" ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1110          $gblDirPerms  = 0755 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1111    
1112          // phpinfo() ;          // phpinfo() ;
1113          // exit ;          // exit ;
# Line 788  the source<BR>of this file.<BR><BR> Line 1121  the source<BR>of this file.<BR><BR>
1121          }          }
1122    
1123          // authentication if $gblAuth == true          // authentication if $gblAuth == true
1124          if ( $gblAuth &&          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1125               $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) {                  isset($relogin) && $gblPw == $relogin ) {
1126                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;
1127                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1128                  NoEntry() ;                  NoEntry() ;
# Line 827  the source<BR>of this file.<BR><BR> Line 1160  the source<BR>of this file.<BR><BR>
1160                    
1161          switch ($POSTACTION) {          switch ($POSTACTION) {
1162          case "UPLOAD" :          case "UPLOAD" :
1163                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1164                  if (strstr($FN_name,"/"))                  if (strstr($FN_name,"/"))
1165                          Error("Non-conforming filename") ;                          Error("Non-conforming filename") ;
1166                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1167                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1168                  $source = $FN ;                  $source = $FN ;
1169                  $target = $fsDir . "/" . $FN_name ;                  if (! isset($FILENAME)) {       // from update file
1170                  exec("cp $source $target") ;                          $target = "$fsDir/$FN_name" ;
1171                  exec("chmod $gblFilePerms $target") ;                  } else {
1172                            $target = "$fsDir/$FILENAME";
1173                    }
1174    
1175                    // backup old files first
1176                    $dir=dirname($target);
1177                    if (! file_exists($dir."/.bak")) {
1178                            mkdir($dir."/.bak",0700);
1179                    }
1180                    if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
1181                            mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
1182                    }
1183                    $file=basename($target);
1184                    for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1185                            MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1186                    }
1187                    MoveTo($target,$dir."/.bak/1/");
1188    
1189                    copy($source,$target) ;
1190                    chmod($target,$gblFilePerms) ;
1191                  clearstatcache() ;                  clearstatcache() ;
1192                    Logit($target,"uploaded");
1193                    if (isset($FILENAME)) {
1194                            Unlock($target);
1195                    }
1196                  break ;                  break ;
1197    
1198          case "SAVE" :          case "SAVE" :
1199                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;
1200                  $writable = Writeable($path) ;                  $writable = is_writeable($path) ;
1201                  $legaldir = Writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1202                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1203  // check for legal extension here as well  // check for legal extension here as well
1204                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
# Line 851  the source<BR>of this file.<BR><BR> Line 1207  the source<BR>of this file.<BR><BR>
1207                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1208                  fclose($fh) ;                  fclose($fh) ;
1209                  clearstatcache() ;                  clearstatcache() ;
1210                    Logit($path,"saved changes");
1211                  break ;                  break ;
1212    
1213          case "CREATE" :          case "CREATE" :
1214                  // we know $fsDir exists                  // we know $fsDir exists
1215                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if ($FN == "") break;           // no filename!
1216                    if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1217                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = $fsDir . "/" . $FN ;  // file or dir to create
1218                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1219                  switch ( $T ) {                  switch ( $T ) {
1220                  case "D" :  // create a directory                  case "D" :  // create a directory
1221                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1222                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1223                    clearstatcache() ;                          clearstatcache() ;
1224                    break ;                          break ;
1225                  case "F" :  // create a new file                  case "F" :  // create a new file
1226  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1227  // better keep it here altogether  // better keep it here altogether
1228  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1229                    if ( file_exists($path) && !Writable($path) )                          if ( file_exists($path) && !is_writable($path) )
1230                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1231                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1232                    header("Location: " . $tstr) ;                          if ($fh) {
1233                    exit ;                                  fputs($fh,"\n");
1234                                    fclose($fh) ;
1235                                    LogIt($path,"file created");
1236                            } else {
1237                                    Error("Creation of file $relPath failed -- $path");
1238                            }
1239                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1240                            header("Location: " . $tstr) ;
1241                            exit ;
1242                  }                  }
1243                  break ;                  break ;
1244    
# Line 883  the source<BR>of this file.<BR><BR> Line 1249  the source<BR>of this file.<BR><BR>
1249                  $tstr .= "insufficient privileges: " ;                  $tstr .= "insufficient privileges: " ;
1250    
1251                  if ( $FN != "") {  // delete file                  if ( $FN != "") {  // delete file
1252                    $path =  $fsDir . "/" . $FN ;                          $path =  $fsDir . "/" . $FN ;
1253                    if ( ! @unlink($path) ) {                  
1254                      Error("File delete failed", $tstr . $path) ;                          $dir=dirname($path);
1255                      exit ;                          $file=basename($path);
1256                    }                                              if (! file_exists("$dir/.del")) {
1257                                    mkdir("$dir/.del",0700);
1258                            }
1259    
1260    //                      if ( ! @unlink($path) ) {
1261                            if ( ! rename($path,"$dir/.del/$file") ) {
1262                                    Error("File delete failed", $tstr . $path) ;
1263                                    Logit($path,"file delete failed");
1264                                    exit ;
1265                            } else {
1266                                    Logit($path,"file deleted");
1267                                    MoveTo("$dir/.log/$file","$dir/.del/.log/");
1268                                    MoveTo("$dir/.note/$file","$dir/.del/.note/");
1269                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1270                            }
1271                  }                  }
1272                  else {  // delete directory                  else {  // delete directory
1273                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rmdir($fsDir) ) {
# Line 899  the source<BR>of this file.<BR><BR> Line 1279  the source<BR>of this file.<BR><BR>
1279                  }                  }
1280                  break ;                  break ;
1281    
1282            case "UNDELETE" :  
1283                    if ( $CONFIRM != "on" ) break ;
1284    
1285                    if (substr($FN,0,4) != ".del") break ;
1286                    $file=substr($FN,4,strlen($FN)-4);
1287    
1288                    Logit("$fsDir/.del/$file","undeleted");
1289                    MoveTo("$fsDir/.del/$file","$fsDir/");
1290                    MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1291                    MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1292                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1293    
1294                    break ;
1295    
1296            case "RENAME" :  
1297                    if ( $CONFIRM != "on" ) break ;
1298    
1299                    Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1300                    safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
1301                    safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1302                    safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1303                    safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1304                    for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1305                            safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
1306                    }
1307    
1308                    break ;
1309    
1310            case "NOTE" :  
1311                    WriteNote("$fsDir/$FN","$NOTE");
1312                    break ;
1313    
1314            case "UNLOCK" :  
1315                    if ( $CONFIRM != "on" ) break ;
1316                    Unlock("$fsDir/$FN");
1317                    break ;
1318    
1319          default :          default :
1320                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1321          }          }
# Line 914  the source<BR>of this file.<BR><BR> Line 1331  the source<BR>of this file.<BR><BR>
1331          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1332          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1333          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1334            // $A=Co : checkout file $D/$F
1335            // $A=Ci : checkin file $D/$F
1336            // $A=V : view file (do nothing except log)
1337          // default : display directory $D          // default : display directory $D
1338                    
1339          switch ($A) {          switch ($A) {
1340          case "U" :          case "U" :
1341                  // upload to $relDir                  // upload to $relDir
1342                  if (!Writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1343                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1344                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1345                  $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 1349  the source<BR>of this file.<BR><BR>
1349                  exit ;                  exit ;
1350          case "E" :          case "E" :
1351                  // detail of $relDir/$F                  // detail of $relDir/$F
1352                  DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1353                  exit ;                  exit ;
1354          case "C" :          case "C" :
1355                  // listing of $relDir/$F                  // listing of $relDir/$F
1356                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1357                  exit ;                  exit ;
1358            case "Co" :
1359                    // checkout
1360                    Lock("$gblFsRoot/$relDir/$F");
1361                    header("Content-Disposition: attachment; filename=$F" );
1362                    Header("Location: ".urlpath("$relDir/$F"));
1363                    exit;
1364            case "Ci" :
1365                    // upload && update to $relDir
1366                    if (!is_writeable($gblFsRoot . $relDir))
1367                            Error("Write access denied",$relDir) ;
1368                    $text  = "Use this page to update a single " ;
1369                    $text .= "file to <B>$SERVER_NAME</B>." ;
1370                    StartHTML("(Update file Page)", $text) ;
1371                    UploadPage($gblFsRoot, $relDir, $F) ;
1372                    EndHTML() ;
1373                    exit ;
1374            case "V" :
1375                    // view
1376                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1377                    header("Content-Disposition: attachment; filename=$F" );
1378                    Header("Location: ".urlpath("$relDir/$F"));
1379                    exit;
1380          }          }
1381    
1382          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.13

  ViewVC Help
Powered by ViewVC 1.1.26