/[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.25 by dpavlin, Thu Dec 21 07:30:04 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    
39            This project is now called Directory Manager.
40    
41            For more info, please see web pages at
42            http://www.rot13.org/~dpavlin/docman.html
43    
44            It's relased under GPL by
45            Dobrica Pavlinusic <dpavlin@rot13.org>
46    
47    
48    IMPORTANT INSTALLATION NOTE:
49            deny serving of .* (dot-something) files in web server!
50            Otherwise, uses can access your log files, users and/or
51            deleted files!
52    
53            .htusers is in form:
54            login:Real Name:md5(loginpassword)
55    
56    
57    TODO:
58            mixed file/directory output (add type to each entry,
59                    real support for links)
60            access controll
61    
62    */
63    
64  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
65    
66  // 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 44  Line 71 
71    
72  // GLOBAL PARAMETERS  // GLOBAL PARAMETERS
73  // =================  // =================
74  // Make modifications here to suit siteman to your needs  // Make modifications here to suit docman to your needs
75    
76  //      error_reporting(4) ;            // how verbose ?  //      error_reporting(4) ;            // how verbose ?
77    
78          // username/password should not be system          // username/password should not be system
79          // usernames/passwords !!          // usernames/passwords !!
80    
81          // your (hashed) username/password here  //      $gblPw    = "hash_of_your_username_and_password" ;
82          $gblPw    = "hash_of_your_username_and_password" ;                
83            //      $gblAuth  = false ;             // use builtin authentication
84          $gblAuth  = false ;             // use builtin authentication          $gblAuth  = true ;             // use builtin authentication
85          $gblHash  = "md5" ;             // hash function to use          $gblHash  = "md5" ;             // hash function to use
86    
87            $gblPw    = "";
88    
89            if ($gblAuth) {
90                    $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
91                    if (! file_exists($htusers_file)) {
92                            $htusers=fopen($htusers_file,"a+");
93                            fputs($htusers,"# Change owner of $htusers_file to root !!\n");
94                            fputs($htusers,"demo:full name:md5_hash\n");
95                            fclose($htusers);
96                    }
97                    $htusers=fopen($htusers_file,"r");
98                    while($user = fgetcsv($htusers,255,":")) {
99                            if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
100                                    $gblUserName=$user[1];
101                                    $gblPw=$user[2];
102                                    $gblEmail=$user[3];
103                                    continue ;
104                            }
105                    }
106                    fclose($htusers);
107            }
108    
109    //      $gblDateFmt="D, F d, Y";
110    //      $gblTimeFmt="g:i:sA";
111    
112            $gblDateFmt="Y-m-d";
113            $gblTimeFmt="H:i:s";
114    
115            // Number of backup files to keep
116            $gblNumBackups=3;
117    
118            // show red star if newer than ... days
119            $gblModDays=1;
120    
121          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
122          // WingDings font installed on your system          // WingDings font installed on your system
123    
# Line 65  Line 126 
126          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
127          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
128    
129          $gblIconLocation = "icons/" ;          $gblIconLocation = "/icons/" ;
130    
131          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
132          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 91  function StartHTML($title,$text="") { Line 152  function StartHTML($title,$text="") {
152    
153  <HTML>  <HTML>
154  <HEAD>  <HEAD>
155   <TITLE><?php echo $host . " " . $title ?></TITLE>   <TITLE><?= $host . " " . $title ?></TITLE>
156   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">
157   <META NAME="keywords" CONTENT="site manager, web site maintenance">   <META NAME="keywords" CONTENT="site manager, web site maintenance">
158   <META NAME="robots" CONTENT="noindex">   <META NAME="robots" CONTENT="noindex">
159   <META HTTP-EQUIV="expires" CONTENT="0">   <META HTTP-EQUIV="expires" CONTENT="0">
160   <LINK REL="stylesheet" TYPE="text/css"   <LINK REL="stylesheet" TYPE="text/css"
161          HREF="<?php echo $self ?>?STYLE=get">          HREF="<?= $self ?>?STYLE=get">
162  </HEAD>  </HEAD>
163  <BODY BGCOLOR="#FFFFFF">  <BODY BGCOLOR="#FFFFFF">
164   <H3 ALIGN="RIGHT"><?php echo $host ?></H3>   <H3 ALIGN="RIGHT"><?= $host ?></H3>
165  <TABLE BORDER=0 WIDTH="100%"><TR>  <TABLE BORDER=0 WIDTH="100%"><TR>
166   <TD CLASS=INV><?php echo $title ?></TD></TR></TABLE>   <TD CLASS=INV><?= $title ?></TD></TR></TABLE>
167   <P><?php echo $text ?></P>   <P><?= $text ?></P>
168    
169  <?php  <?php
170  } // end function StartHTML  } // end function StartHTML
# Line 115  function EndHTML() { Line 176  function EndHTML() {
176    
177  <HR>  <HR>
178  <P CLASS=FTR>  <P CLASS=FTR>
179  <B><?php echo date("D, F d, Y") ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
180  <?php echo date("g:i:sA") ?></B><BR>ANYPORTAL(php) Site Manager  <?= date($GLOBALS[gblTimeFmt]) ?> -
181  - &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>  <?= $GLOBALS[gblUserName] ?>
182  - &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>
183    </B>
184    <BR>ANYPORTAL(php) Site Manager
185    <br><small>
186    &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
187    &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
188    &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
189    </small>
190  </P>  </P>
191  <BR><BR><BR></BODY></HTML>  <BR>
192    <? //include(".debug.inc") ?>
193    <BR><BR></BODY></HTML>
194    
195  <?php  <?php
196  } // end function EndHTML  } // end function EndHTML
# Line 130  function EndHTML() { Line 200  function EndHTML() {
200  function CSS() {  function CSS() {
201  ?>  ?>
202    
203  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; }
204  .BLK { color:black; }  .BLK { color:black; }
205  .RED { color:red; }  .RED { color:red; }
206  .TOP { color:red; font-size:70%; } /* table headings */  .TOP { color:red; font-size:70%; } /* table headings */
# Line 164  function DetailPage($fsRoot,$relDir,$fn) Line 234  function DetailPage($fsRoot,$relDir,$fn)
234          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
235          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
236          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
237          $writable = Writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
238            $file_lock = CheckLock($fsPath);
239    
240          if (!$editable && !$exists)          if (!$editable && !$exists)
241                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
242          if (!exists && !Writeable($fsDir) )          if (!exists && !is_writeable($fsDir) )
243                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
244    
245          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
# Line 179  function DetailPage($fsRoot,$relDir,$fn) Line 250  function DetailPage($fsRoot,$relDir,$fn)
250    
251          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;
252          if ($exists) {  // get file info          if ($exists) {  // get file info
253            $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
254            $fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
255            $faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
256            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;
257            echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
258            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
259            echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;
260            echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;
261            echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
262            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
263            echo "</PRE>" ;                  echo "</PRE>" ;
264    
265          }          }
266    
267          if ( $editable && ($writable || !$exists) ) {          if ( $editable && ($writable || !$exists) && !$file_lock ) {
268                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
269                  rewind($fh) ;                  rewind($fh) ;
270                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 200  function DetailPage($fsRoot,$relDir,$fn) Line 272  function DetailPage($fsRoot,$relDir,$fn)
272                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
273  ?>  ?>
274    
275  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
276  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
277          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
278  </SPAN><BR>  </SPAN><BR>
279  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
280  echo($fstr) ; ?></TEXTAREA>  echo($fstr) ; ?></TEXTAREA>
281  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
282  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
283  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
284  <INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
285          VALUE="<?php echo $relPath ; ?>">          VALUE="<?= $relPath ; ?>">
286  <INPUT TYPE="RESET" VALUE="RESET">  <br>
287    <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
288  <INPUT TYPE="SUBMIT" VALUE="SAVE">  <INPUT TYPE="SUBMIT" VALUE="SAVE">
289  </FORM>  </FORM>
290    
291  <?php  <?php
292          }          }
293          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
294            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
295            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
296            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
297            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
298            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
299                    echo $tstr ;
300          }          }
301    
302  ?>  ?>
303    
304  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
305  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
306  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
307  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
308    
309  <?php  <?php
310    
311            if ($file_lock) {
312    ?>
313    <hr>
314    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
315    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
316    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
317    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
318    <?
319            } // file_lock
320    
321            if (substr($fn,0,4) == ".del") {
322                    $action="UNDELETE";
323                    $desc="undelete previously deleted file";
324            } else {
325                    $action="DELETE";
326                    $desc="delete";
327            }
328    
329          if ($exists && $writable) {          if ($exists && $writable) {
330  ?>  ?>
331    
332  <HR><SPAN TITLE="Check OK and click [DELETE] to delete.">  <HR>
333  <B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN>  <a name="undelete">
334    <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
335    <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>
336    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
337    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
338    
339    <HR>
340    <a name="rename">
341    <SPAN TITLE="Check OK and click [RENAME] to rename.">
342    <B>OK TO RENAME "<?= $fn ; ?>" TO
343    <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
344    ? </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="RENAME">
347    
348    <?php
349            }       // exists && writable
350    ?>
351    <HR>
352    <a name="note">
353    <B>NOTE FOR "<?= $fn ; ?>":
354    <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">
355    </B></SPAN>
356    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
357    
358    </FORM>
359    
360  <?php  <?php
361    
362            $name=basename("$fsDir/$fn");
363            $logname=dirname("$fsDir/$fn")."/.log/$name";
364            $bakdir=dirname("$fsDir/$fn")."/.bak";
365            if (file_exists($logname)) {
366                    $log=fopen($logname,"r");
367                    $cl1=" class=lst"; $cl2="";
368                    $logarr = array();
369                    while($line = fgetcsv($log,255,"\t")) {
370                            $cl=$cl1; $cl1=$cl2; $cl2=$cl;
371                            array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
372                    }
373                    fclose($log);
374                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
375                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
376                    while ($e = array_shift($logarr)) {
377                            if (strstr($e[4],"upload")) {
378                                    if (file_exists("$bakdir/$bakcount/$name")) {
379                                            $e[4]="<a href=\"".dirname($relPath)."/.bak/$bakcount/$name\">$e[4]</a>";
380                                    }
381                                    $bakcount++;
382                            }
383                            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";
384                    }
385                    print "</table>";
386          }          }
387          echo "</FORM>" ;  
388          EndHTML() ;          EndHTML() ;
389    
390  } // end function DetailPage  } // end function DetailPage
# Line 472  function GifIcon($txt) { Line 614  function GifIcon($txt) {
614          case "blank" :          case "blank" :
615                  $d = "blank.gif" ;                  $d = "blank.gif" ;
616                  break ;                  break ;
617            case "checkout":
618                    $d = "box2.gif";
619                    break;
620            case "checkin":
621                    $d = "hand.up.gif";
622                    break;
623            case "locked":
624                    $d = "screw2.gif";
625                    break;
626            case "note":
627                    $d = "quill.gif";
628                    break;
629          default :          default :
630                  $d = "generic.gif" ;                  $d = "generic.gif" ;
631          }          }
# Line 483  function GifIcon($txt) { Line 637  function GifIcon($txt) {
637    
638  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
639    
640          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays ;
641    
642          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
643          $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
644                    $webRoot  = "https://" . $GLOBALS["HTTP_HOST"] ;
645            } else {
646                    $webRoot  = "http://" . $GLOBALS["HTTP_HOST"] ;
647            }
648          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir    = $fsRoot . $relDir . "/" ; // current directory
649    
650          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 653  function Navigate($fsRoot,$relDir) {
653          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
654                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
655          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
656                  if ( $item == ".." || $item == "." ) continue ;                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;
657                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
658                          $dirList[] = $item ;                          $dirList[] = $item ;
659                  }                  } else if ( is_file($fsDir . $item) ) {
                 else if ( is_file($fsDir . $item) ) {  
660                          $fileList[] = $item ;                                    $fileList[] = $item ;          
661                  }                  } else if ( is_link($fsDir . $item) ) {
662                  else {                          $dirList[] = $item ;
663                    } else {
664                    // unknown file type                    // unknown file type
665                    // $text = "Could not determine file type of " ;                    // $text = "Could not determine file type of " ;
666                    // Error("File Error", $text.$relDir."/".$item) ;                    // Error("File Error", $text.$relDir."/".$item) ;
# Line 510  function Navigate($fsRoot,$relDir) { Line 668  function Navigate($fsRoot,$relDir) {
668                  }                  }
669          }          }
670          closedir($dir) ;          closedir($dir) ;
671    
672            // scan deleted files
673            if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
674                    while ($item = readdir($dir)) {
675                            if ( substr($item,0,1) == "." ) continue ;
676                            $fileList[] = ".del/$item" ;            
677                    }
678                    closedir($dir) ;
679            }
680    
681          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
682    
683          // start navigation page          // start navigation page
684          $text  = "Use this page to add, delete or " ;          $text  = "Use this page to add, delete";
685          $text .= "revise files on this web site." ;          if (! isset($show_deleted)) {
686                    $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
687            }
688            $text .= " or revise files on this web site." ;
689            $text .= "<br>Examine list of files <a href=\"$self?A=Ch1\">changed in last day</a> or <a href=\"$self?A=Ch\">all changes</a>.";
690          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
691    
692          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 527  function Navigate($fsRoot,$relDir) { Line 698  function Navigate($fsRoot,$relDir) {
698                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
699  ?>  ?>
700    
701  <TR><TD><?php echo $gblIcon("up") ?></TD><TD COLSPAN=4 CLASS=LST>  <TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST>
702  <A HREF="<?php echo $self ?>?D=<?php echo urlencode($parent) ?>">  <A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>">
703  <B><?php echo $parent ?></B></A></TD></TR>  <B><?= $parent ?></B></A></TD></TR>
704    
705  <?php  <?php
706          }          }
# Line 539  function Navigate($fsRoot,$relDir) { Line 710  function Navigate($fsRoot,$relDir) {
710                  sort($dirList) ;                  sort($dirList) ;
711  ?>  ?>
712    
713  <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>
714    
715  <?php  <?php
716                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
# Line 549  function Navigate($fsRoot,$relDir) { Line 720  function Navigate($fsRoot,$relDir) {
720                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
721  ?>  ?>
722    
723  <TR><TD><?php echo $gblIcon("fldr") ?></TD>  <TR><TD><?= $gblIcon("fldr") ?></TD>
724  <TD COLSPAN=4 CLASS=LST><?php echo $tstr ?></TD></TR>  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>
725    
726  <?php  <?php
727                  }  // iterate over dirs                  }  // iterate over dirs
728          }  // end if no dirs          }  // end if no dirs
729  ?>  ?>
730    
731  <TR><TD></TD><TD COLSPAN=4><HR><B><?php echo $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
732  </B></TD></TR>  </B></TD></TR>
733  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
734  <TD><?php echo $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
735    <TD CLASS=TOP>NOTE</TD>
736  <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>
737    
738  <?php  <?php
739          if (sizeof($fileList) > 0) {          if (sizeof($fileList) > 0) {
740            sort($fileList) ;            sort($fileList) ;
741            while (list($key,$file) = each($fileList)) {              while (list($key,$file) = each($fileList)) {  
742              $path = $fsDir."/".$file ;                  $path = $fsDir."/".$file ;
743              $mod  = filemtime($path) ;                  $mod  = filemtime($path) ;
744              $sz   = filesize($path) ;                  $sz   = filesize($path) ;
745    
746              if ($sz >= 10240) {                  if ($sz >= 10240) {
747                $sz = (int)(($sz+1023)/1024) . " k" ;                          $sz = (int)(($sz+1023)/1024) . " k" ;
748              }                  } else {
749              else {                          $sz .= " " ;
750                $sz .= " " ;                  } // end size
751              } // end size  
752                    $a = $b = "" ;
753              $a = $b = "" ;  
754                    $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
755              if ( ($mod + 30*86400) > time() ) {  
756                $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                  if ( ($mod + $gblModDays*86400) > time() ) {
757                $a .= " than 30 days\"> * </SPAN>" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
758              }                          $a .= " than $gblModDays days\"> * </SPAN>" ;
759                    }
760              $tstr = $webRoot . $relDir . "/" . $file ;  
761              $tstr  = "<A HREF=\"" . $tstr . "\">" ;                  $file_lock=CheckLock($path);
762              $tstr .= $file . "</A>" . $a ;  
763                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
764              $ext = strtolower(strrchr($file,".")) ;                  $file_url_html.="&D=".urlencode($relDir);
765              if ( $ext=="" ||                  $file_url_html.="\" TITLE=\"View file\">" ;
766                   strstr(join(" ",$gblEditable),$ext) )  
767              {                    if (substr($file,0,5) != ".del/") {
768                $b  = "<A HREF=\"" . $self . "?A=C&F=" ;                          $file_url_html .= $file . "</A>" . $a ;
769                $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                  } else {
770                $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>";
771                $b .= $gblIcon("view") . "</A>" ;                  }
772              }  
773                    $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
774    
775                    $ext = strtolower(strrchr($file,".")) ;
776    
777                    if ($file_lock) {
778                            if ($file_lock == $GLOBALS[gblUserName]) {
779                                    $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
780                                    $b.="&D=".urlencode($relDir);
781                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
782                                    $file_url_html=$b;
783                                    $b.=$gblIcon("checkin")."</A>" ;
784                                    $b.= $gblIcon("blank");
785                                    $file_url_html.="$file</a> $a";
786                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
787                            } else {
788                                    $b = $gblIcon("locked");
789                                    $b.= $gblIcon("blank");
790                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
791                                    $file_url_html = "$file $a";
792                            }
793                    } else {
794                            $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
795                            $b.="&D=".urlencode($relDir);
796                            $b.="\" TITLE=\"Checkout file for edit\">" ;
797                            $b.=$gblIcon("checkout")."</A>" ;
798    
799                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
800                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
801                                    $b.="&D=".urlencode($relDir);
802                                    $b.="\" TITLE=\"List contents\">" ;
803                                    $b.=$gblIcon("view")."</A>" ;
804                            } else {
805                                    $b.= $gblIcon("blank");
806                            }
807                    }
808    
809    
810  ?>  ?>
811    
812  <TR><TD>  <TR><TD>
813  <A HREF="<?php echo $self ?>?A=E&F=<?php echo urlencode($file)  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
814  ?>&D=<?php echo urlencode($relDir) ?>" TITLE="View/Edit">  <?= $gblIcon($ext) ?></A></TD>
815  <?php echo $gblIcon($ext) ?></A></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
816  <TD CLASS=LST><?php echo $tstr ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
817  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
818  <TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
819  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
820    
821  <?php  <?php
822            }  // iterate over files            }  // iterate over files
823          }  // end if no files          } else {  // end if no files
824    ?>
825     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
826      No files in this directory
827     </TD></TR>
828    <?
829            }
830    
831          if ($emptyDir) {          if ($emptyDir) {
832  ?>  ?>
833    
834  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
835   <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>   <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
836    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
837    OK TO DELETE THIS EMPTY FOLDER?    OK TO DELETE THIS EMPTY FOLDER?
838    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
839    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
# Line 630  function Navigate($fsRoot,$relDir) { Line 844  function Navigate($fsRoot,$relDir) {
844          } // end if emptyDir          } // end if emptyDir
845  ?>  ?>
846    
847  <TR><TD></TD><TD COLSPAN=4><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
848    
849    <?
850    if (file_exists(".info.inc")) {
851            print "<TR><TD></TD><TD COLSPAN=5>";
852            include(".info.inc");
853            print "</TD></TR>
854            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
855    }
856    ?>
857    
858  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
859  <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
860   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
861   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
862   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
863   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
864   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
865   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
866   <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  
867   </NOBR>   </NOBR>
868  </TD></TR>  </TD></TR>
869  </FORM>  </FORM>
# Line 653  function Navigate($fsRoot,$relDir) { Line 875  function Navigate($fsRoot,$relDir) {
875    
876  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
877    
878  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename) {
879    
880          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
881          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 661  function UploadPage($fsRoot, $relDir) { Line 883  function UploadPage($fsRoot, $relDir) {
883    
884  <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>
885  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
886   ACTION="<?php echo $self ?>">   ACTION="<?= $self ?>">
887  DESTINATION DIRECTORY:<B><?php echo " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
888    <? if (isset($filename)) { ?>
889    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
890    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
891    <? } ?>
892  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
893  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
894  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
895  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
896  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
897  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
898  you must upgrade to an RFC1867-compliant browser.</P>  you must upgrade to an RFC1867-compliant browser.</P>
899  <P>Your browser:<BR><?php echo $GLOBALS["HTTP_USER_AGENT"] ?></P>  <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
900  </FORM>  </FORM>
901  </TD></TR>  </TD></TR>
902  <TR><TD></TD><TD>  <TR><TD></TD><TD>
903  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
904  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>"><BR>  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
905  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
906  </FORM>  </FORM>
907  </TD></TR></TABLE></P>  </TD></TR></TABLE></P>
# Line 694  function Error($title,$text="") { Line 920  function Error($title,$text="") {
920    
921  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
922    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
923  function CreateHash($user, $pw) {  function CreateHash($user, $pw) {
924    
925          global $gblHash ;  // hash function to use          global $gblHash ;  // hash function to use
# Line 749  function NoEntry() { Line 954  function NoEntry() {
954          StartHTML($title,$text) ;          StartHTML($title,$text) ;
955  ?>  ?>
956    
957  <FORM ACTION="<?php echo $self ?>?HASH=create" METHOD="POST">  <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">
958  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?php echo $user ?>">  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">
959  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?php echo $pw ?>">  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $pw ?>">
960    
961  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>
962  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 972  the source<BR>of this file.<BR><BR>
972    
973  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
974    
975    function LogIt($target,$msg) {
976    
977            $dir=dirname($target);
978            if (! file_exists($dir."/.log")) {
979                    mkdir($dir."/.log",0700);
980            }
981            $file=basename($target);
982    
983            $log=fopen("$dir/.log/$file","a+");
984            fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
985                    "\t$GLOBALS[gblUserName]\t$msg\n");
986            fclose($log);
987    
988    }
989    
990    
991    //////////////////////////////////////////////////////////////////
992    
993    function WriteNote($target,$msg) {
994    
995            $target=stripSlashes($target);
996            $dir=dirname($target);
997            if (! file_exists($dir."/.note")) {
998                    mkdir($dir."/.note",0700);
999            }
1000            $file=basename($target);
1001    
1002            $note=fopen("$dir/.note/$file","w");
1003            fputs($note,"$msg\n");
1004            fclose($note);
1005    
1006            Logit($target,"added note $msg");
1007    
1008    }
1009    
1010    function ReadNote($target) {
1011    
1012            $target=stripSlashes($target);
1013            $dir=dirname($target);
1014            $file=basename($target);
1015            $msg="";
1016            if (file_exists($dir."/.note/$file")) {
1017                    $note=fopen("$dir/.note/$file","r");
1018                    $msg=fgets($note,4096);
1019                    fclose($note);
1020            }
1021            return StripSlashes($msg);
1022    
1023    }
1024    
1025    //////////////////////////////////////////////////////////////////
1026    
1027    function MoveTo($source,$folder) {
1028    
1029            $source=stripSlashes($source);
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            $target=stripSlashes($target);
1044            $dir=dirname($target);
1045            if (! file_exists($dir."/.lock")) {
1046                    mkdir($dir."/.lock",0700);
1047            }
1048            $file=basename($target);
1049    
1050            if (file_exists("$dir/.lock/$file")) {
1051                    Logit($target,"attempt to locked allready locked file!");
1052            } else {
1053                    $lock=fopen("$dir/.lock/$file","w");
1054                    fputs($lock,"$GLOBALS[gblUserName]\n");
1055                    fclose($lock);
1056    
1057                    Logit($target,"file locked");
1058            }
1059    
1060    }
1061    
1062    function CheckLock($target) {
1063    
1064            $target=stripSlashes($target);
1065            $dir=dirname($target);
1066            $file=basename($target);
1067            $msg=0;
1068            if (file_exists($dir."/.lock/$file")) {
1069                    $lock=fopen("$dir/.lock/$file","r");
1070                    $msg=fgets($lock,4096);
1071                    fclose($lock);
1072            }
1073            return chop($msg);
1074    
1075    }
1076    
1077    function Unlock($target) {
1078    
1079            $target=stripSlashes($target);
1080            $dir=dirname($target);
1081            $file=basename($target);
1082            if (file_exists($dir."/.lock/$file")) {
1083                    unlink("$dir/.lock/$file");
1084                    Logit($target,"file unlocked");
1085            } else {
1086                    Logit($target,"attempt to unlocked non-locked file!");
1087            }
1088    
1089    }
1090    
1091    //////////////////////////////////////////////////////////////////
1092    
1093    function urlpath($url) {
1094            $url=urlencode(StripSlashes("$url"));
1095            $url=str_replace("%2F","/",$url);
1096            $url=str_replace("+","%20",$url);
1097            return($url);
1098    }
1099    
1100    //////////////////////////////////////////////////////////////////
1101    
1102    function safe_rename($from,$to) {
1103            if (file_exists($from) && is_writable(dirname($to))) {
1104                    rename($from,$to);
1105            }
1106    }
1107    
1108    //////////////////////////////////////////////////////////////////
1109    
1110    // recursivly delete directory
1111    
1112    function rrmdir($dir) {
1113            $handle=opendir($dir);
1114            while ($file = readdir($handle)) {
1115                    if ($file != "." && $file != "..") {
1116                            if (is_dir("$dir/$file"))
1117                                    rrmdir("$dir/$file");
1118                            else
1119                                    if (! @unlink("$dir/$file")) return(0);
1120                    }
1121            }
1122            closedir($handle);
1123            return @rmdir($dir);
1124    }
1125    
1126    //////////////////////////////////////////////////////////////////
1127    
1128    function ChangeLog($target,$msg) {
1129    
1130            global $gblFsRoot;
1131            $log=fopen("$gblFsRoot/.changelog","a+");
1132            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1133                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1134            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1135            fclose($log);
1136    
1137    }
1138    
1139    function DisplayChangeLog($day) {
1140    
1141            global $gblFsRoot;
1142            if (!file_exists("$gblFsRoot/.changelog")) return;
1143            $log=fopen("$gblFsRoot/.changelog","r");
1144            $logarr = array();
1145            while($line = fgetcsv($log,255,"\t")) {
1146                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1147                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1148                    }
1149            }
1150            fclose($log);
1151            $cl1=" class=lst"; $cl2="";
1152            print "<table border=0 width=100%>\n";
1153            while ($e = array_shift($logarr)) {
1154                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1155                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1156                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1157                    $dir = dirname($e[1]);
1158                    $file = basename($e[1]);
1159                    print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$GLOBALS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n";
1160            }
1161            print "</table>";
1162            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1163    }
1164    
1165    //////////////////////////////////////////////////////////////////
1166    
1167  // MAIN PROGRAM  // MAIN PROGRAM
1168  // ============  // ============
1169  // query parameters: capital letters  // query parameters: capital letters
1170  // local functions : begin with capital letters  // local functions : begin with capital letters
1171  // global constants: begin with gbl  // global constants: begin with gbl
1172    
1173          $gblFilePerms = "644" ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1174          $gblDirPerms  = 0755 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1175    
1176          // phpinfo() ;          // phpinfo() ;
1177          // exit ;          // exit ;
# Line 788  the source<BR>of this file.<BR><BR> Line 1185  the source<BR>of this file.<BR><BR>
1185          }          }
1186    
1187          // authentication if $gblAuth == true          // authentication if $gblAuth == true
1188          if ( $gblAuth &&          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1189               $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) {                  isset($relogin) && $gblPw == $relogin ) {
1190                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1191                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1192                  NoEntry() ;                  NoEntry() ;
1193                  exit ;                  exit ;
# Line 813  the source<BR>of this file.<BR><BR> Line 1210  the source<BR>of this file.<BR><BR>
1210          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1211    
1212          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1213          // i.e. /siteman          // i.e. /docman
1214    
1215          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1216          // i.e. /home/httpd/html/siteman          // i.e. /home/httpd/html/docman
1217    
1218          $gblFsRoot = substr($fsScriptDir,0,          // start on server root
1219            strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1220            // or on script root
1221            $gblFsRoot = $fsScriptDir;
1222          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1223    
1224          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1225          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1226            
1227            $FN=stripSlashes($FN);
1228    
1229          switch ($POSTACTION) {          switch ($POSTACTION) {
1230          case "UPLOAD" :          case "UPLOAD" :
1231                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1232                  if (strstr($FN_name,"/"))                  if (strstr($FN_name,"/"))
1233                          Error("Non-conforming filename") ;                          Error("Non-conforming filename") ;
1234                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1235                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1236                  $source = $FN ;                  $source = $FN ;
1237                  $target = $fsDir . "/" . $FN_name ;                  if (! isset($FILENAME)) {       // from update file
1238                  exec("cp $source $target") ;                          $target = "$fsDir/$FN_name" ;
1239                  exec("chmod $gblFilePerms $target") ;                  } else {
1240                            $target = "$fsDir/$FILENAME";
1241                    }
1242    
1243                    // backup old files first
1244                    $dir=dirname($target);
1245                    if (! file_exists($dir."/.bak")) {
1246                            mkdir($dir."/.bak",0700);
1247                    }
1248                    if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
1249                            mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
1250                    }
1251                    $file=basename($target);
1252                    for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1253                            MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1254                    }
1255                    MoveTo($target,$dir."/.bak/1/");
1256    
1257                    copy($source,$target) ;
1258                    chmod($target,$gblFilePerms) ;
1259                  clearstatcache() ;                  clearstatcache() ;
1260                    Logit($target,"uploaded");
1261                    if (isset($FILENAME)) {
1262                            Unlock($target);
1263                    }
1264                    ChangeLog($target,"updated");
1265                  break ;                  break ;
1266    
1267          case "SAVE" :          case "SAVE" :
1268                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1269                  $writable = Writeable($path) ;                  $path=stripSlashes($path);
1270                  $legaldir = Writeable(dirname($path)) ;                  $writable = is_writeable($path) ;
1271                    $legaldir = is_writeable(dirname($path)) ;
1272                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1273  // check for legal extension here as well  // check for legal extension here as well
1274                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1275                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1276                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1277                    $FILEDATA=stripSlashes($FILEDATA);
1278                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1279                  fclose($fh) ;                  fclose($fh) ;
1280                  clearstatcache() ;                  clearstatcache() ;
1281                    Logit($path,"saved changes");
1282                    ChangeLog($path,"saved changes");
1283                  break ;                  break ;
1284    
1285          case "CREATE" :          case "CREATE" :
1286                  // we know $fsDir exists                  // we know $fsDir exists
1287                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if ($FN == "") break;           // no filename!
1288                    if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1289                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = $fsDir . "/" . $FN ;  // file or dir to create
1290                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1291                  switch ( $T ) {                  switch ( $T ) {
1292                  case "D" :  // create a directory                  case "D" :  // create a directory
1293                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1294                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1295                    clearstatcache() ;                          clearstatcache() ;
1296                    break ;                          break ;
1297                  case "F" :  // create a new file                  case "F" :  // create a new file
1298  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1299  // better keep it here altogether  // better keep it here altogether
1300  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1301                    if ( file_exists($path) && !Writable($path) )                          if ( file_exists($path) && !is_writable($path) )
1302                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1303                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1304                    header("Location: " . $tstr) ;                          if ($fh) {
1305                    exit ;                                  fputs($fh,"\n");
1306                                    fclose($fh) ;
1307                                    LogIt($path,"file created");
1308                            } else {
1309                                    Error("Creation of file $relPath failed -- $path");
1310                            }
1311                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1312                            header("Location: " . $tstr) ;
1313                            ChangeLog($target,"created");
1314                            exit ;
1315                  }                  }
1316                  break ;                  break ;
1317    
# Line 883  the source<BR>of this file.<BR><BR> Line 1322  the source<BR>of this file.<BR><BR>
1322                  $tstr .= "insufficient privileges: " ;                  $tstr .= "insufficient privileges: " ;
1323    
1324                  if ( $FN != "") {  // delete file                  if ( $FN != "") {  // delete file
1325                    $path =  $fsDir . "/" . $FN ;                          $path =  $fsDir . "/" . $FN ;
1326                    if ( ! @unlink($path) ) {                  
1327                      Error("File delete failed", $tstr . $path) ;                          $dir=dirname($path);
1328                      exit ;                          $file=basename($path);
1329                    }                                              if (! file_exists("$dir/.del")) {
1330                                    mkdir("$dir/.del",0700);
1331                            }
1332    
1333    //                      if ( ! @unlink($path) ) {
1334                            if ( ! rename($path,"$dir/.del/$file") ) {
1335                                    Error("File delete failed", $tstr . $path) ;
1336                                    Logit($path,"file delete failed");
1337                                    exit ;
1338                            } else {
1339                                    Logit($path,"file deleted");
1340                                    MoveTo("$dir/.log/$file","$dir/.del/.log/");
1341                                    MoveTo("$dir/.note/$file","$dir/.del/.note/");
1342                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1343                            }
1344                  }                  }
1345                  else {  // delete directory                  else {  // delete directory
1346                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1347                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1348                    }                    }
1349                    else {                    else {
# Line 899  the source<BR>of this file.<BR><BR> Line 1352  the source<BR>of this file.<BR><BR>
1352                  }                  }
1353                  break ;                  break ;
1354    
1355            case "UNDELETE" :  
1356                    if ( $CONFIRM != "on" ) break ;
1357    
1358                    if (substr($FN,0,4) != ".del") break ;
1359                    $file=substr($FN,4,strlen($FN)-4);
1360    
1361                    Logit("$fsDir/.del/$file","undeleted");
1362                    MoveTo("$fsDir/.del/$file","$fsDir/");
1363                    MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1364                    MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1365                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1366    
1367                    break ;
1368    
1369            case "RENAME" :  
1370                    if ( $CONFIRM != "on" ) break ;
1371    
1372                    Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1373                    safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
1374                    safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1375                    safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1376                    safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1377                    for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1378                            safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
1379                    }
1380    
1381                    break ;
1382    
1383            case "NOTE" :  
1384                    WriteNote("$fsDir/$FN","$NOTE");
1385                    break ;
1386    
1387            case "UNLOCK" :  
1388                    if ( $CONFIRM != "on" ) break ;
1389                    Unlock("$fsDir/$FN");
1390                    break ;
1391    
1392          default :          default :
1393                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1394          }          }
# Line 914  the source<BR>of this file.<BR><BR> Line 1404  the source<BR>of this file.<BR><BR>
1404          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1405          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1406          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1407            // $A=Co : checkout file $D/$F
1408            // $A=Ci : checkin file $D/$F
1409            // $A=V : view file (do nothing except log)
1410          // default : display directory $D          // default : display directory $D
1411            
1412          switch ($A) {          switch ($A) {
1413          case "U" :          case "U" :
1414                  // upload to $relDir                  // upload to $relDir
1415                  if (!Writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1416                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1417                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1418                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1419                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1420                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1421                  EndHTML() ;                  EndHTML() ;
1422                  exit ;                  exit ;
1423          case "E" :          case "E" :
1424                    $F=stripSlashes($F);
1425                  // detail of $relDir/$F                  // detail of $relDir/$F
1426                  DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1427                  exit ;                  exit ;
1428          case "C" :          case "C" :
1429                    $F=stripSlashes($F);
1430                  // listing of $relDir/$F                  // listing of $relDir/$F
1431                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1432                  exit ;                  exit ;
1433            case "Co" :
1434                    // checkout
1435                    Lock("$gblFsRoot/$relDir/$F");
1436                    header("Content-Disposition: attachment; filename=$F" );
1437                    Header("Location: ".urlpath("$relDir/$F"));
1438                    exit;
1439            case "Ci" :
1440                    $F=stripSlashes($F);
1441                    // upload && update to $relDir
1442                    if (!is_writeable($gblFsRoot . $relDir))
1443                            Error("Write access denied",$relDir) ;
1444                    $text  = "Use this page to update a single " ;
1445                    $text .= "file to <B>$HTTP_HOST</B>." ;
1446                    StartHTML("(Update file Page)", $text) ;
1447                    UploadPage($gblFsRoot, $relDir, $F) ;
1448                    EndHTML() ;
1449                    exit ;
1450            case "V" :
1451                    // view
1452                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1453                    header("Content-Disposition: attachment; filename=$F" );
1454                    Header("Location: ".urlpath("$relDir/$F"));
1455                    exit;
1456            case "Ch" :
1457                    StartHTML("(File changes)","All changes chronologicaly...");
1458                    DisplayChangeLog(0);    // all
1459                    EndHTML() ;
1460                    exit;
1461            case "Ch1" :
1462                    StartHTML("(File changes)","Changes to files in last day...");
1463                    DisplayChangeLog(1);
1464                    EndHTML() ;
1465                    exit;
1466          }          }
1467    
1468          // default: display directory $relDir          // default: display directory $relDir

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

  ViewVC Help
Powered by ViewVC 1.1.26