/[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.16 by dpavlin, Wed Sep 6 14:06:02 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                                    $gblEmail=$user[3];
112                                    continue ;
113                            }
114                    }
115                    fclose($htusers);
116            }
117    
118    //      $gblDateFmt="D, F d, Y";
119    //      $gblTimeFmt="g:i:sA";
120    
121            $gblDateFmt="Y-m-d";
122            $gblTimeFmt="H:i:s";
123    
124            // Number of backup files to keep
125            $gblNumBackups=3;
126    
127            // show red star if newer than ... days
128            $gblModDays=1;
129    
130          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
131          // WingDings font installed on your system          // WingDings font installed on your system
132    
# Line 65  Line 135 
135          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
136          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
137    
138          $gblIconLocation = "icons/" ;          $gblIconLocation = "/icons/" ;
139    
140          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
141          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 91  function StartHTML($title,$text="") { Line 161  function StartHTML($title,$text="") {
161    
162  <HTML>  <HTML>
163  <HEAD>  <HEAD>
164   <TITLE><?php echo $host . " " . $title ?></TITLE>   <TITLE><?= $host . " " . $title ?></TITLE>
165   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">
166   <META NAME="keywords" CONTENT="site manager, web site maintenance">   <META NAME="keywords" CONTENT="site manager, web site maintenance">
167   <META NAME="robots" CONTENT="noindex">   <META NAME="robots" CONTENT="noindex">
168   <META HTTP-EQUIV="expires" CONTENT="0">   <META HTTP-EQUIV="expires" CONTENT="0">
169   <LINK REL="stylesheet" TYPE="text/css"   <LINK REL="stylesheet" TYPE="text/css"
170          HREF="<?php echo $self ?>?STYLE=get">          HREF="<?= $self ?>?STYLE=get">
171  </HEAD>  </HEAD>
172  <BODY BGCOLOR="#FFFFFF">  <BODY BGCOLOR="#FFFFFF">
173   <H3 ALIGN="RIGHT"><?php echo $host ?></H3>   <H3 ALIGN="RIGHT"><?= $host ?></H3>
174  <TABLE BORDER=0 WIDTH="100%"><TR>  <TABLE BORDER=0 WIDTH="100%"><TR>
175   <TD CLASS=INV><?php echo $title ?></TD></TR></TABLE>   <TD CLASS=INV><?= $title ?></TD></TR></TABLE>
176   <P><?php echo $text ?></P>   <P><?= $text ?></P>
177    
178  <?php  <?php
179  } // end function StartHTML  } // end function StartHTML
# Line 115  function EndHTML() { Line 185  function EndHTML() {
185    
186  <HR>  <HR>
187  <P CLASS=FTR>  <P CLASS=FTR>
188  <B><?php echo date("D, F d, Y") ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
189  <?php echo date("g:i:sA") ?></B><BR>ANYPORTAL(php) Site Manager  <?= date($GLOBALS[gblTimeFmt]) ?> -
190  - &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>  <?= $GLOBALS[gblUserName] ?>
191  - &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>
192    </B>
193    <BR>ANYPORTAL(php) Site Manager
194    <br><small>
195    &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
196    &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
197    &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
198    </small>
199  </P>  </P>
200  <BR><BR><BR></BODY></HTML>  <BR>
201    <? //include(".debug.inc") ?>
202    <BR><BR></BODY></HTML>
203    
204  <?php  <?php
205  } // end function EndHTML  } // end function EndHTML
# Line 130  function EndHTML() { Line 209  function EndHTML() {
209  function CSS() {  function CSS() {
210  ?>  ?>
211    
212  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; }
213  .BLK { color:black; }  .BLK { color:black; }
214  .RED { color:red; }  .RED { color:red; }
215  .TOP { color:red; font-size:70%; } /* table headings */  .TOP { color:red; font-size:70%; } /* table headings */
# Line 164  function DetailPage($fsRoot,$relDir,$fn) Line 243  function DetailPage($fsRoot,$relDir,$fn)
243          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
244          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
245          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
246          $writable = Writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
247            $file_lock = CheckLock($fsPath);
248    
249          if (!$editable && !$exists)          if (!$editable && !$exists)
250                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
251          if (!exists && !Writeable($fsDir) )          if (!exists && !is_writeable($fsDir) )
252                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
253    
254          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
# Line 179  function DetailPage($fsRoot,$relDir,$fn) Line 259  function DetailPage($fsRoot,$relDir,$fn)
259    
260          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;
261          if ($exists) {  // get file info          if ($exists) {  // get file info
262            $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
263            $fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
264            $faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
265            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;
266            echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
267            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
268            echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;
269            echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;
270            echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
271            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
272            echo "</PRE>" ;                  echo "</PRE>" ;
273    
274          }          }
275    
276          if ( $editable && ($writable || !$exists) ) {          if ( $editable && ($writable || !$exists) && !$file_lock ) {
277                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
278                  rewind($fh) ;                  rewind($fh) ;
279                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 200  function DetailPage($fsRoot,$relDir,$fn) Line 281  function DetailPage($fsRoot,$relDir,$fn)
281                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
282  ?>  ?>
283    
284  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
285  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
286          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
287  </SPAN><BR>  </SPAN><BR>
288  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
289  echo($fstr) ; ?></TEXTAREA>  echo($fstr) ; ?></TEXTAREA>
290  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
291  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
292  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
293  <INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
294          VALUE="<?php echo $relPath ; ?>">          VALUE="<?= $relPath ; ?>">
295  <INPUT TYPE="RESET" VALUE="RESET">  <br>
296    <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
297  <INPUT TYPE="SUBMIT" VALUE="SAVE">  <INPUT TYPE="SUBMIT" VALUE="SAVE">
298  </FORM>  </FORM>
299    
300  <?php  <?php
301          }          }
302          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
303            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
304            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
305            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
306            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
307            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
308                    echo $tstr ;
309          }          }
310    
311  ?>  ?>
312    
313  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
314  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
315  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
316  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
317    
318  <?php  <?php
319    
320            if ($file_lock) {
321    ?>
322    <hr>
323    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
324    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
325    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
326    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
327    <?
328            } // file_lock
329    
330            if (substr($fn,0,4) == ".del") {
331                    $action="UNDELETE";
332                    $desc="undelete previously deleted file";
333            } else {
334                    $action="DELETE";
335                    $desc="delete";
336            }
337    
338          if ($exists && $writable) {          if ($exists && $writable) {
339  ?>  ?>
340    
341  <HR><SPAN TITLE="Check OK and click [DELETE] to delete.">  <HR>
342  <B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN>  <a name="undelete">
343    <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
344    <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>
345  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
346  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
347    
348    <HR>
349    <a name="rename">
350    <SPAN TITLE="Check OK and click [RENAME] to rename.">
351    <B>OK TO RENAME "<?= $fn ; ?>" TO
352    <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
353    ? </B></SPAN>
354    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
355    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
356    
357    <?php
358            }       // exists && writable
359    ?>
360    <HR>
361    <a name="note">
362    <B>NOTE FOR "<?= $fn ; ?>":
363    <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">
364    </B></SPAN>
365    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
366    
367    </FORM>
368    
369  <?php  <?php
370            
371            $name=basename("$fsDir/$fn");
372            $logname=dirname("$fsDir/$fn")."/.log/$name";
373            $bakdir=dirname("$fsDir/$fn")."/.bak";
374            if (file_exists($logname)) {
375                    $log=fopen($logname,"r");
376                    $cl1=" class=lst"; $cl2="";
377                    $logarr = array();
378                    while($line = fgetcsv($log,255,"\t")) {
379                            $cl=$cl1; $cl1=$cl2; $cl2=$cl;
380                            array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
381                    }
382                    fclose($log);
383                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
384                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
385                    while ($e = array_shift($logarr)) {
386                            if (strstr($e[4],"upload")) {
387                                    if (file_exists("$bakdir/$bakcount/$name")) {
388                                            $e[4]="<a href=\"".dirname($relPath)."/.bak/$bakcount/$name\">$e[4]</a>";
389                                    }
390                                    $bakcount++;
391                            }
392                            print "<tr><td$e[0]>$e[1]</td><td$e[0]>$e[2]</td><td$e[0]>$e[3]</td><td$e[0]>$e[4]</td></tr>\n";
393                    }
394                    print "</table>";
395          }          }
396          echo "</FORM>" ;  
397          EndHTML() ;          EndHTML() ;
398    
399  } // end function DetailPage  } // end function DetailPage
# Line 472  function GifIcon($txt) { Line 623  function GifIcon($txt) {
623          case "blank" :          case "blank" :
624                  $d = "blank.gif" ;                  $d = "blank.gif" ;
625                  break ;                  break ;
626            case "checkout":
627                    $d = "box2.gif";
628                    break;
629            case "checkin":
630                    $d = "hand.up.gif";
631                    break;
632            case "locked":
633                    $d = "screw2.gif";
634                    break;
635            case "note":
636                    $d = "quill.gif";
637                    break;
638          default :          default :
639                  $d = "generic.gif" ;                  $d = "generic.gif" ;
640          }          }
# Line 483  function GifIcon($txt) { Line 646  function GifIcon($txt) {
646    
647  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
648    
649          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays ;
650    
651          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
652          $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
653                    $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;
654            } else {
655                    $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;
656            }
657          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir    = $fsRoot . $relDir . "/" ; // current directory
658    
659          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 662  function Navigate($fsRoot,$relDir) {
662          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
663                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
664          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
665                  if ( $item == ".." || $item == "." ) continue ;                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;
666                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
667                          $dirList[] = $item ;                          $dirList[] = $item ;
668                  }                  } else if ( is_file($fsDir . $item) ) {
                 else if ( is_file($fsDir . $item) ) {  
669                          $fileList[] = $item ;                                    $fileList[] = $item ;          
670                  }                  } else if ( is_link($fsDir . $item) ) {
671                  else {                          $dirList[] = $item ;
672                    } else {
673                    // unknown file type                    // unknown file type
674                    // $text = "Could not determine file type of " ;                    // $text = "Could not determine file type of " ;
675                    // Error("File Error", $text.$relDir."/".$item) ;                    // Error("File Error", $text.$relDir."/".$item) ;
# Line 510  function Navigate($fsRoot,$relDir) { Line 677  function Navigate($fsRoot,$relDir) {
677                  }                  }
678          }          }
679          closedir($dir) ;          closedir($dir) ;
680    
681            // scan deleted files
682            if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
683                    while ($item = readdir($dir)) {
684                            if ( substr($item,0,1) == "." ) continue ;
685                            $fileList[] = ".del/$item" ;            
686                    }
687                    closedir($dir) ;
688            }
689    
690          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
691    
692          // start navigation page          // start navigation page
693          $text  = "Use this page to add, delete or " ;          $text  = "Use this page to add, delete";
694          $text .= "revise files on this web site." ;          if (! isset($show_deleted)) {
695                    $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
696            }
697            $text .= " or revise files on this web site." ;
698          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
699    
700          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 527  function Navigate($fsRoot,$relDir) { Line 706  function Navigate($fsRoot,$relDir) {
706                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
707  ?>  ?>
708    
709  <TR><TD><?php echo $gblIcon("up") ?></TD><TD COLSPAN=4 CLASS=LST>  <TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST>
710  <A HREF="<?php echo $self ?>?D=<?php echo urlencode($parent) ?>">  <A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>">
711  <B><?php echo $parent ?></B></A></TD></TR>  <B><?= $parent ?></B></A></TD></TR>
712    
713  <?php  <?php
714          }          }
# Line 539  function Navigate($fsRoot,$relDir) { Line 718  function Navigate($fsRoot,$relDir) {
718                  sort($dirList) ;                  sort($dirList) ;
719  ?>  ?>
720    
721  <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>
722    
723  <?php  <?php
724                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
# Line 549  function Navigate($fsRoot,$relDir) { Line 728  function Navigate($fsRoot,$relDir) {
728                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
729  ?>  ?>
730    
731  <TR><TD><?php echo $gblIcon("fldr") ?></TD>  <TR><TD><?= $gblIcon("fldr") ?></TD>
732  <TD COLSPAN=4 CLASS=LST><?php echo $tstr ?></TD></TR>  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>
733    
734  <?php  <?php
735                  }  // iterate over dirs                  }  // iterate over dirs
736          }  // end if no dirs          }  // end if no dirs
737  ?>  ?>
738    
739  <TR><TD></TD><TD COLSPAN=4><HR><B><?php echo $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
740  </B></TD></TR>  </B></TD></TR>
741  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
742  <TD><?php echo $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
743    <TD CLASS=TOP>NOTE</TD>
744  <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>
745    
746  <?php  <?php
747          if (sizeof($fileList) > 0) {          if (sizeof($fileList) > 0) {
748            sort($fileList) ;            sort($fileList) ;
749            while (list($key,$file) = each($fileList)) {              while (list($key,$file) = each($fileList)) {  
750              $path = $fsDir."/".$file ;                  $path = $fsDir."/".$file ;
751              $mod  = filemtime($path) ;                  $mod  = filemtime($path) ;
752              $sz   = filesize($path) ;                  $sz   = filesize($path) ;
753    
754              if ($sz >= 10240) {                  if ($sz >= 10240) {
755                $sz = (int)(($sz+1023)/1024) . " k" ;                          $sz = (int)(($sz+1023)/1024) . " k" ;
756              }                  } else {
757              else {                          $sz .= " " ;
758                $sz .= " " ;                  } // end size
759              } // end size  
760                    $a = $b = "" ;
761              $a = $b = "" ;  
762                    $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
763              if ( ($mod + 30*86400) > time() ) {  
764                $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                  if ( ($mod + $gblModDays*86400) > time() ) {
765                $a .= " than 30 days\"> * </SPAN>" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
766              }                          $a .= " than $gblModDays days\"> * </SPAN>" ;
767                    }
768              $tstr = $webRoot . $relDir . "/" . $file ;  
769              $tstr  = "<A HREF=\"" . $tstr . "\">" ;                  $file_lock=CheckLock($path);
770              $tstr .= $file . "</A>" . $a ;  
771                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
772              $ext = strtolower(strrchr($file,".")) ;                  $file_url_html.="&D=".urlencode($relDir);
773              if ( $ext=="" ||                  $file_url_html.="\" TITLE=\"View file\">" ;
774                   strstr(join(" ",$gblEditable),$ext) )  
775              {                    if (substr($file,0,5) != ".del/") {
776                $b  = "<A HREF=\"" . $self . "?A=C&F=" ;                          $file_url_html .= $file . "</A>" . $a ;
777                $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                  } else {
778                $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>";
779                $b .= $gblIcon("view") . "</A>" ;                  }
780              }  
781                    $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
782    
783                    $ext = strtolower(strrchr($file,".")) ;
784    
785                    if ($file_lock) {
786                            if ($file_lock == $GLOBALS[gblUserName]) {
787                                    $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
788                                    $b.="&D=".urlencode($relDir);
789                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
790                                    $file_url_html=$b;
791                                    $b.=$gblIcon("checkin")."</A>" ;
792                                    $b.= $gblIcon("blank");
793                                    $file_url_html.="$file</a> $a";
794                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
795                            } else {
796                                    $b = $gblIcon("locked");
797                                    $b.= $gblIcon("blank");
798                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
799                                    $file_url_html = "$file $a";
800                            }
801                    } else {
802                            $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
803                            $b.="&D=".urlencode($relDir);
804                            $b.="\" TITLE=\"Checkout file for edit\">" ;
805                            $b.=$gblIcon("checkout")."</A>" ;
806    
807                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
808                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
809                                    $b.="&D=".urlencode($relDir);
810                                    $b.="\" TITLE=\"List contents\">" ;
811                                    $b.=$gblIcon("view")."</A>" ;
812                            } else {
813                                    $b.= $gblIcon("blank");
814                            }
815                    }
816    
817    
818  ?>  ?>
819    
820  <TR><TD>  <TR><TD>
821  <A HREF="<?php echo $self ?>?A=E&F=<?php echo urlencode($file)  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
822  ?>&D=<?php echo urlencode($relDir) ?>" TITLE="View/Edit">  <?= $gblIcon($ext) ?></A></TD>
823  <?php echo $gblIcon($ext) ?></A></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
824  <TD CLASS=LST><?php echo $tstr ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
825  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
826  <TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
827  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
828    
829  <?php  <?php
830            }  // iterate over files            }  // iterate over files
# Line 617  function Navigate($fsRoot,$relDir) { Line 833  function Navigate($fsRoot,$relDir) {
833          if ($emptyDir) {          if ($emptyDir) {
834  ?>  ?>
835    
836  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
837   <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>   <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
838    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
839    OK TO DELETE THIS EMPTY FOLDER?    OK TO DELETE THIS EMPTY FOLDER?
840    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
841    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
# Line 630  function Navigate($fsRoot,$relDir) { Line 846  function Navigate($fsRoot,$relDir) {
846          } // end if emptyDir          } // end if emptyDir
847  ?>  ?>
848    
849  <TR><TD></TD><TD COLSPAN=4><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
850    
851    <TR><TD></TD><TD COLSPAN=5>
852    <?
853    if (file_exists(".info.inc")) {
854            include(".info.inc");
855    }
856    ?>
857    </TD></TR>
858    
859  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
860  <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>CREATE NEW  
861    <FORM METHOD="POST" ACTION="<?= $self ?>">
862    <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
863   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
864   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
865   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
866   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
867   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
868   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
869   <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  
870   </NOBR>   </NOBR>
871  </TD></TR>  </TD></TR>
872  </FORM>  </FORM>
# Line 653  function Navigate($fsRoot,$relDir) { Line 878  function Navigate($fsRoot,$relDir) {
878    
879  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
880    
881  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename) {
882    
883          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
884          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 661  function UploadPage($fsRoot, $relDir) { Line 886  function UploadPage($fsRoot, $relDir) {
886    
887  <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>
888  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
889   ACTION="<?php echo $self ?>">   ACTION="<?= $self ?>">
890  DESTINATION DIRECTORY:<B><?php echo " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
891    <? if (isset($filename)) { ?>
892    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
893    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
894    <? } ?>
895  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
896  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
897  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
898  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
899  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
900  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
901  you must upgrade to an RFC1867-compliant browser.</P>  you must upgrade to an RFC1867-compliant browser.</P>
902  <P>Your browser:<BR><?php echo $GLOBALS["HTTP_USER_AGENT"] ?></P>  <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
903  </FORM>  </FORM>
904  </TD></TR>  </TD></TR>
905  <TR><TD></TD><TD>  <TR><TD></TD><TD>
906  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
907  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>"><BR>  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
908  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
909  </FORM>  </FORM>
910  </TD></TR></TABLE></P>  </TD></TR></TABLE></P>
# Line 694  function Error($title,$text="") { Line 923  function Error($title,$text="") {
923    
924  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
925    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
926  function CreateHash($user, $pw) {  function CreateHash($user, $pw) {
927    
928          global $gblHash ;  // hash function to use          global $gblHash ;  // hash function to use
# Line 749  function NoEntry() { Line 957  function NoEntry() {
957          StartHTML($title,$text) ;          StartHTML($title,$text) ;
958  ?>  ?>
959    
960  <FORM ACTION="<?php echo $self ?>?HASH=create" METHOD="POST">  <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">
961  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?php echo $user ?>">  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">
962  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?php echo $pw ?>">  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $pw ?>">
963    
964  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>
965  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 975  the source<BR>of this file.<BR><BR>
975    
976  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
977    
978    function Logit($target,$msg) {
979    
980            $dir=dirname($target);
981            if (! file_exists($dir."/.log")) {
982                    mkdir($dir."/.log",0700);
983            }
984            $file=basename($target);
985    
986            $log=fopen("$dir/.log/$file","a+");
987            fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
988                    "\t$GLOBALS[gblUserName]\t$msg\n");
989            fclose($log);
990    
991    }
992    
993    
994    //////////////////////////////////////////////////////////////////
995    
996    function WriteNote($target,$msg) {
997    
998            $dir=dirname($target);
999            if (! file_exists($dir."/.note")) {
1000                    mkdir($dir."/.note",0700);
1001            }
1002            $file=basename($target);
1003    
1004            $note=fopen("$dir/.note/$file","w");
1005            fputs($note,"$msg\n");
1006            fclose($note);
1007    
1008            Logit($target,"added note $msg");
1009    
1010    }
1011    
1012    function ReadNote($target) {
1013    
1014            $dir=dirname($target);
1015            $file=basename($target);
1016            $msg="";
1017            if (file_exists($dir."/.note/$file")) {
1018                    $note=fopen("$dir/.note/$file","r");
1019                    $msg=fgets($note,4096);
1020                    fclose($note);
1021            }
1022            return StripSlashes($msg);
1023    
1024    }
1025    
1026    //////////////////////////////////////////////////////////////////
1027    
1028    function MoveTo($source,$folder) {
1029    
1030            $file=basename($source);
1031            if (! file_exists($folder)) {
1032                    mkdir($folder,0700);
1033            }
1034            if (file_exists($source)) {
1035                    rename($source,"$folder/$file");
1036            }
1037    }
1038    
1039    //////////////////////////////////////////////////////////////////
1040    
1041    function Lock($target) {
1042    
1043            $dir=dirname($target);
1044            if (! file_exists($dir."/.lock")) {
1045                    mkdir($dir."/.lock",0700);
1046            }
1047            $file=basename($target);
1048    
1049            if (file_exists("$dir/.lock/$file")) {
1050                    Logit($target,"attempt to locked allready locked file!");
1051            } else {
1052                    $lock=fopen("$dir/.lock/$file","w");
1053                    fputs($lock,"$GLOBALS[gblUserName]\n");
1054                    fclose($lock);
1055    
1056                    Logit($target,"file locked");
1057            }
1058    
1059    }
1060    
1061    function CheckLock($target) {
1062    
1063            $dir=dirname($target);
1064            $file=basename($target);
1065            $msg=0;
1066            if (file_exists($dir."/.lock/$file")) {
1067                    $lock=fopen("$dir/.lock/$file","r");
1068                    $msg=fgets($lock,4096);
1069                    fclose($lock);
1070            }
1071            return chop($msg);
1072    
1073    }
1074    
1075    function Unlock($target) {
1076    
1077            $dir=dirname($target);
1078            $file=basename($target);
1079            if (file_exists($dir."/.lock/$file")) {
1080                    unlink("$dir/.lock/$file");
1081                    Logit($target,"file unlocked");
1082            } else {
1083                    Logit($target,"attempt to unlocked non-locked file!");
1084            }
1085    
1086    }
1087    
1088    //////////////////////////////////////////////////////////////////
1089    
1090    function urlpath($url) {
1091            $url=urlencode(StripSlashes("$url"));
1092            $url=str_replace("%2F","/",$url);
1093            $url=str_replace("+","%20",$url);
1094            return($url);
1095    }
1096    
1097    //////////////////////////////////////////////////////////////////
1098    
1099    function safe_rename($from,$to) {
1100            if (file_exists($from) && is_writable(dirname($to))) {
1101                    rename($from,$to);
1102            }
1103    }
1104    
1105    //////////////////////////////////////////////////////////////////
1106    
1107    // recursivly delete directory
1108    
1109    function rrmdir($dir) {
1110            $handle=opendir($dir);
1111            while ($file = readdir($handle)) {
1112                    if ($file != "." && $file != "..") {
1113                            if (is_dir("$dir/$file"))
1114                                    rrmdir("$dir/$file");
1115                            else
1116                                    if (! @unlink("$dir/$file")) return(0);
1117                    }
1118            }
1119            closedir($handle);
1120            return @rmdir($dir);
1121    }
1122    
1123    //////////////////////////////////////////////////////////////////
1124    
1125  // MAIN PROGRAM  // MAIN PROGRAM
1126  // ============  // ============
1127  // query parameters: capital letters  // query parameters: capital letters
1128  // local functions : begin with capital letters  // local functions : begin with capital letters
1129  // global constants: begin with gbl  // global constants: begin with gbl
1130    
1131          $gblFilePerms = "644" ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1132          $gblDirPerms  = 0755 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1133    
1134          // phpinfo() ;          // phpinfo() ;
1135          // exit ;          // exit ;
# Line 788  the source<BR>of this file.<BR><BR> Line 1143  the source<BR>of this file.<BR><BR>
1143          }          }
1144    
1145          // authentication if $gblAuth == true          // authentication if $gblAuth == true
1146          if ( $gblAuth &&          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1147               $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) {                  isset($relogin) && $gblPw == $relogin ) {
1148                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;
1149                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1150                  NoEntry() ;                  NoEntry() ;
# Line 827  the source<BR>of this file.<BR><BR> Line 1182  the source<BR>of this file.<BR><BR>
1182                    
1183          switch ($POSTACTION) {          switch ($POSTACTION) {
1184          case "UPLOAD" :          case "UPLOAD" :
1185                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1186                  if (strstr($FN_name,"/"))                  if (strstr($FN_name,"/"))
1187                          Error("Non-conforming filename") ;                          Error("Non-conforming filename") ;
1188                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1189                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1190                  $source = $FN ;                  $source = $FN ;
1191                  $target = $fsDir . "/" . $FN_name ;                  if (! isset($FILENAME)) {       // from update file
1192                  exec("cp $source $target") ;                          $target = "$fsDir/$FN_name" ;
1193                  exec("chmod $gblFilePerms $target") ;                  } else {
1194                            $target = "$fsDir/$FILENAME";
1195                    }
1196    
1197                    // backup old files first
1198                    $dir=dirname($target);
1199                    if (! file_exists($dir."/.bak")) {
1200                            mkdir($dir."/.bak",0700);
1201                    }
1202                    if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
1203                            mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
1204                    }
1205                    $file=basename($target);
1206                    for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1207                            MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1208                    }
1209                    MoveTo($target,$dir."/.bak/1/");
1210    
1211                    copy($source,$target) ;
1212                    chmod($target,$gblFilePerms) ;
1213                  clearstatcache() ;                  clearstatcache() ;
1214                    Logit($target,"uploaded");
1215                    if (isset($FILENAME)) {
1216                            Unlock($target);
1217                    }
1218                  break ;                  break ;
1219    
1220          case "SAVE" :          case "SAVE" :
1221                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;
1222                  $writable = Writeable($path) ;                  $writable = is_writeable($path) ;
1223                  $legaldir = Writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1224                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1225  // check for legal extension here as well  // check for legal extension here as well
1226                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
# Line 851  the source<BR>of this file.<BR><BR> Line 1229  the source<BR>of this file.<BR><BR>
1229                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1230                  fclose($fh) ;                  fclose($fh) ;
1231                  clearstatcache() ;                  clearstatcache() ;
1232                    Logit($path,"saved changes");
1233                  break ;                  break ;
1234    
1235          case "CREATE" :          case "CREATE" :
1236                  // we know $fsDir exists                  // we know $fsDir exists
1237                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if ($FN == "") break;           // no filename!
1238                    if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1239                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = $fsDir . "/" . $FN ;  // file or dir to create
1240                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1241                  switch ( $T ) {                  switch ( $T ) {
1242                  case "D" :  // create a directory                  case "D" :  // create a directory
1243                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1244                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1245                    clearstatcache() ;                          clearstatcache() ;
1246                    break ;                          break ;
1247                  case "F" :  // create a new file                  case "F" :  // create a new file
1248  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1249  // better keep it here altogether  // better keep it here altogether
1250  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1251                    if ( file_exists($path) && !Writable($path) )                          if ( file_exists($path) && !is_writable($path) )
1252                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1253                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1254                    header("Location: " . $tstr) ;                          if ($fh) {
1255                    exit ;                                  fputs($fh,"\n");
1256                                    fclose($fh) ;
1257                                    LogIt($path,"file created");
1258                            } else {
1259                                    Error("Creation of file $relPath failed -- $path");
1260                            }
1261                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1262                            header("Location: " . $tstr) ;
1263                            exit ;
1264                  }                  }
1265                  break ;                  break ;
1266    
# Line 883  the source<BR>of this file.<BR><BR> Line 1271  the source<BR>of this file.<BR><BR>
1271                  $tstr .= "insufficient privileges: " ;                  $tstr .= "insufficient privileges: " ;
1272    
1273                  if ( $FN != "") {  // delete file                  if ( $FN != "") {  // delete file
1274                    $path =  $fsDir . "/" . $FN ;                          $path =  $fsDir . "/" . $FN ;
1275                    if ( ! @unlink($path) ) {                  
1276                      Error("File delete failed", $tstr . $path) ;                          $dir=dirname($path);
1277                      exit ;                          $file=basename($path);
1278                    }                                              if (! file_exists("$dir/.del")) {
1279                                    mkdir("$dir/.del",0700);
1280                            }
1281    
1282    //                      if ( ! @unlink($path) ) {
1283                            if ( ! rename($path,"$dir/.del/$file") ) {
1284                                    Error("File delete failed", $tstr . $path) ;
1285                                    Logit($path,"file delete failed");
1286                                    exit ;
1287                            } else {
1288                                    Logit($path,"file deleted");
1289                                    MoveTo("$dir/.log/$file","$dir/.del/.log/");
1290                                    MoveTo("$dir/.note/$file","$dir/.del/.note/");
1291                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1292                            }
1293                  }                  }
1294                  else {  // delete directory                  else {  // delete directory
1295                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1296                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1297                    }                    }
1298                    else {                    else {
# Line 899  the source<BR>of this file.<BR><BR> Line 1301  the source<BR>of this file.<BR><BR>
1301                  }                  }
1302                  break ;                  break ;
1303    
1304            case "UNDELETE" :  
1305                    if ( $CONFIRM != "on" ) break ;
1306    
1307                    if (substr($FN,0,4) != ".del") break ;
1308                    $file=substr($FN,4,strlen($FN)-4);
1309    
1310                    Logit("$fsDir/.del/$file","undeleted");
1311                    MoveTo("$fsDir/.del/$file","$fsDir/");
1312                    MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1313                    MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1314                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1315    
1316                    break ;
1317    
1318            case "RENAME" :  
1319                    if ( $CONFIRM != "on" ) break ;
1320    
1321                    Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1322                    safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
1323                    safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1324                    safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1325                    safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1326                    for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1327                            safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
1328                    }
1329    
1330                    break ;
1331    
1332            case "NOTE" :  
1333                    WriteNote("$fsDir/$FN","$NOTE");
1334                    break ;
1335    
1336            case "UNLOCK" :  
1337                    if ( $CONFIRM != "on" ) break ;
1338                    Unlock("$fsDir/$FN");
1339                    break ;
1340    
1341          default :          default :
1342                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1343          }          }
# Line 914  the source<BR>of this file.<BR><BR> Line 1353  the source<BR>of this file.<BR><BR>
1353          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1354          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1355          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1356            // $A=Co : checkout file $D/$F
1357            // $A=Ci : checkin file $D/$F
1358            // $A=V : view file (do nothing except log)
1359          // default : display directory $D          // default : display directory $D
1360                    
1361          switch ($A) {          switch ($A) {
1362          case "U" :          case "U" :
1363                  // upload to $relDir                  // upload to $relDir
1364                  if (!Writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1365                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1366                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1367                  $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 1371  the source<BR>of this file.<BR><BR>
1371                  exit ;                  exit ;
1372          case "E" :          case "E" :
1373                  // detail of $relDir/$F                  // detail of $relDir/$F
1374                  DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1375                  exit ;                  exit ;
1376          case "C" :          case "C" :
1377                  // listing of $relDir/$F                  // listing of $relDir/$F
1378                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1379                  exit ;                  exit ;
1380            case "Co" :
1381                    // checkout
1382                    Lock("$gblFsRoot/$relDir/$F");
1383                    header("Content-Disposition: attachment; filename=$F" );
1384                    Header("Location: ".urlpath("$relDir/$F"));
1385                    exit;
1386            case "Ci" :
1387                    // upload && update to $relDir
1388                    if (!is_writeable($gblFsRoot . $relDir))
1389                            Error("Write access denied",$relDir) ;
1390                    $text  = "Use this page to update a single " ;
1391                    $text .= "file to <B>$SERVER_NAME</B>." ;
1392                    StartHTML("(Update file Page)", $text) ;
1393                    UploadPage($gblFsRoot, $relDir, $F) ;
1394                    EndHTML() ;
1395                    exit ;
1396            case "V" :
1397                    // view
1398                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1399                    header("Content-Disposition: attachment; filename=$F" );
1400                    Header("Location: ".urlpath("$relDir/$F"));
1401                    exit;
1402          }          }
1403    
1404          // default: display directory $relDir          // default: display directory $relDir

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

  ViewVC Help
Powered by ViewVC 1.1.26