/[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.44 by dpavlin, Thu Jun 21 08:54:54 2001 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)|auth_*]:email@host.dom
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            // from where to include auth_*.php modules?
79            $gblIncDir = "/home/httpd/docman";
80    
81          // username/password should not be system          // username/password should not be system
82          // usernames/passwords !!          // usernames/passwords !!
83    
84          // your (hashed) username/password here          $gblPw    = "";
85          $gblPw    = "hash_of_your_username_and_password" ;                
86                    // date format
87          $gblAuth  = false ;             // use builtin authentication  //      $gblDateFmt="D, F d, Y";
88          $gblHash  = "md5" ;             // hash function to use          $gblDateFmt="Y-m-d";
89    
90            // time format
91    //      $gblTimeFmt="g:i:sA";
92            $gblTimeFmt="H:i:s";
93    
94            // Number of backup files to keep
95            $gblNumBackups=3;
96    
97            // show red star if newer than ... days
98            $gblModDays=1;
99    
100          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
101          // WingDings font installed on your system          // WingDings font installed on your system
102    
103          $gblIcon = "GifIcon" ;          // MockIcon or GifIcon          $gblIcon="GifIcon";             // MockIcon or GifIcon
104    
105          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
106          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
107    
108          $gblIconLocation = "icons/" ;          $gblIconLocation="/icons/";
109    
110          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
111          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 80  Line 120 
120          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",
121                                ".bmp",".xbm") ;                                ".bmp",".xbm") ;
122    
123            // which files to hide (separated by ,)
124            $gblHide = "";
125    
126            // Where are users? (by default in .htusers file)
127            $gblUsers = "htusers_file";
128    
129  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
130    
131  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
132    
133          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
134          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
135          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
136  ?>  ?>
137    
138  <HTML>  <HTML>
139  <HEAD>  <HEAD>
140   <TITLE><?php echo $host . " " . $title ?></TITLE>   <TITLE><?= $host . " " . $title ?></TITLE>
141   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">
142   <META NAME="keywords" CONTENT="site manager, web site maintenance">   <META NAME="keywords" CONTENT="site manager, web site maintenance">
143   <META NAME="robots" CONTENT="noindex">   <META NAME="robots" CONTENT="noindex">
144   <META HTTP-EQUIV="expires" CONTENT="0">   <META HTTP-EQUIV="expires" CONTENT="0">
145   <LINK REL="stylesheet" TYPE="text/css"   <LINK REL="stylesheet" TYPE="text/css"
146          HREF="<?php echo $self ?>?STYLE=get">          HREF="<?= $self ?>?STYLE=get">
147  </HEAD>  </HEAD>
148  <BODY BGCOLOR="#FFFFFF">  <BODY BGCOLOR="#FFFFFF">
149   <H3 ALIGN="RIGHT"><?php echo $host ?></H3>   <H3 ALIGN="RIGHT"><?= $host ?></H3>
150  <TABLE BORDER=0 WIDTH="100%"><TR>  <TABLE BORDER=0 WIDTH="100%"><TR>
151   <TD CLASS=INV><?php echo $title ?></TD></TR></TABLE>   <TD CLASS=INV><?= $title ?></TD></TR></TABLE>
152   <P><?php echo $text ?></P>   <P><?= $text ?></P>
153    
154  <?php  <?php
155  } // end function StartHTML  } // end function StartHTML
# Line 115  function EndHTML() { Line 161  function EndHTML() {
161    
162  <HR>  <HR>
163  <P CLASS=FTR>  <P CLASS=FTR>
164  <B><?php echo date("D, F d, Y") ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
165  <?php echo date("g:i:sA") ?></B><BR>ANYPORTAL(php) Site Manager  <?= date($GLOBALS[gblTimeFmt]) ?> -
166  - &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>  <?= $GLOBALS[gblUserName] ?>
167  - &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>
168    </B>
169    <BR>ANYPORTAL(php) Site Manager
170    <br><small>
171    &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
172    &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
173    &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
174    </small>
175  </P>  </P>
176  <BR><BR><BR></BODY></HTML>  <BR>
177    <? //include(".debug.inc") ?>
178    <BR><BR></BODY></HTML>
179    
180  <?php  <?php
181  } // end function EndHTML  } // end function EndHTML
# Line 130  function EndHTML() { Line 185  function EndHTML() {
185  function CSS() {  function CSS() {
186  ?>  ?>
187    
188  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; }
189  .BLK { color:black; }  .BLK { color:black; }
190  .RED { color:red; }  .RED { color:red; }
191  .TOP { color:red; font-size:70%; } /* table headings */  .TOP { color:red; font-size:70%; } /* table headings */
# Line 154  A:HOVER { color:red; } Line 209  A:HOVER { color:red; }
209    
210  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
211                    
212          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
213          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
214    
215          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 164  function DetailPage($fsRoot,$relDir,$fn) Line 219  function DetailPage($fsRoot,$relDir,$fn)
219          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
220          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
221          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
222          $writable = Writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
223            $file_lock = CheckLock($fsPath);
224    
225          if (!$editable && !$exists)          if (!$editable && !$exists)
226                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
227          if (!exists && !Writeable($fsDir) )          if (!exists && !is_writeable($fsDir) )
228                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
229    
230          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
231          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
232                    $text .="delete a directory on this " ;
233            } else {
234                    $text .= "delete a single document on this " ;
235            };
236          $text .= "web site." ;            $text .= "web site." ;  
237          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
238          StartHTML($title, $text) ;          StartHTML($title, $text) ;
239    
240          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;
241          if ($exists) {  // get file info          if ($exists) {  // get file info
242            $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
243            $fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
244            $faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
245            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
246            echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  $fgid=filegroup($fsPath);
247            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  $userinfo = posix_getpwuid($fuid);
248            echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  $grpinfo = posix_getgrgid($fgid);
249            echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "<PRE>";
250            echo "  permissions: <B>" ;                  if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
251            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
252            echo "</PRE>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
253                    echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
254                    echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
255                    echo "  permissions: <B>" ;
256                    echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
257                    echo "</PRE>" ;
258    
259          }          }
260    
261          if ( $editable && ($writable || !$exists) ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
262                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
263                  rewind($fh) ;                  rewind($fh) ;
264                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 200  function DetailPage($fsRoot,$relDir,$fn) Line 266  function DetailPage($fsRoot,$relDir,$fn)
266                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
267  ?>  ?>
268    
269  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
270  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
271          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
272  </SPAN><BR>  </SPAN><BR>
273  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
274  echo($fstr) ; ?></TEXTAREA>  echo($fstr) ; ?></TEXTAREA>
275  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
276  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
277  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
278  <INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
279          VALUE="<?php echo $relPath ; ?>">          VALUE="<?= $relPath ; ?>">
280  <INPUT TYPE="RESET" VALUE="RESET">  <br>
281    <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
282  <INPUT TYPE="SUBMIT" VALUE="SAVE">  <INPUT TYPE="SUBMIT" VALUE="SAVE">
283  </FORM>  </FORM>
284    
285  <?php  <?php
286          }          }
287          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
288            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
289            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
290            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
291            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
292            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
293                    echo $tstr ;
294          }          }
295    
296  ?>  ?>
297    
298  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
299  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
300  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
301  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
302    
303  <?php  <?php
304    
305            if ($file_lock) {
306    ?>
307    <hr>
308    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
309    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
310    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
311    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
312    <?
313            } // file_lock
314    
315            if (substr($fn,0,4) == ".del") {
316                    $action="UNDELETE";
317                    $desc="undelete previously deleted file";
318            } else {
319                    $action="DELETE";
320                    $desc="delete";
321            }
322    
323          if ($exists && $writable) {          if ($exists && $writable) {
324  ?>  ?>
325    
326  <HR><SPAN TITLE="Check OK and click [DELETE] to delete.">  <HR>
327  <B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN>  <a name="undelete">
328    <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
329    <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>
330    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
331    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
332    
333    <HR>
334    <a name="rename">
335    <SPAN TITLE="Check OK and click [RENAME] to rename.">
336    <B>OK TO RENAME "<?= $fn ; ?>" TO
337    <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
338    ? </B></SPAN>
339  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
340  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
341    
342    <?php
343            }       // exists && writable
344    ?>
345    <HR>
346    <a name="note">
347    <B>NOTE FOR "<?= $fn ; ?>":
348    <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">
349    </B></SPAN>
350    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
351    
352    </FORM>
353    
354  <?php  <?php
355    
356            $name=basename("$fsDir/$fn");
357            $logname=dirname("$fsDir/$fn")."/.log/$name";
358            $bakdir=dirname("$fsDir/$fn")."/.bak";
359            if (file_exists($logname)) {
360                    $log=fopen($logname,"r");
361                    $cl1=" class=LST"; $cl2="";
362                    $logarr = array();
363                    while($line = fgetcsv($log,255,"\t")) {
364                            $cl=$cl1; $cl1=$cl2; $cl2=$cl;
365                            array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
366                    }
367                    fclose($log);
368                    if (is_dir("$fsDir/$fn")) {
369                            $whatis="DIRECTORY";
370                    } else {
371                            $whatis="FILE";
372                    }
373                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
374                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
375                    while ($e = array_shift($logarr)) {
376                            if (strstr($e[4],"upload")) {
377                                    if (file_exists("$bakdir/$bakcount/$name")) {
378                                            $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
379                                    }
380                                    $bakcount++;
381                            }
382                            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";
383                    }
384                    print "</table>";
385          }          }
386          echo "</FORM>" ;  
387          EndHTML() ;          EndHTML() ;
388    
389  } // end function DetailPage  } // end function DetailPage
# Line 472  function GifIcon($txt) { Line 613  function GifIcon($txt) {
613          case "blank" :          case "blank" :
614                  $d = "blank.gif" ;                  $d = "blank.gif" ;
615                  break ;                  break ;
616            case "checkout":
617                    $d = "box2.gif";
618                    break;
619            case "checkin":
620                    $d = "hand.up.gif";
621                    break;
622            case "locked":
623                    $d = "screw2.gif";
624                    break;
625            case "note":
626                    $d = "quill.gif";
627                    break;
628          default :          default :
629                  $d = "generic.gif" ;                  $d = "generic.gif" ;
630          }          }
# Line 483  function GifIcon($txt) { Line 636  function GifIcon($txt) {
636    
637  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
638    
639          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ;
640    
641          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
642          $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;  
643          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir = $fsRoot . $relDir . "/" ; // current directory
644    
645          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
646    
647            $hide_items=",$gblHide,";
648    
649          // read directory contents          // read directory contents
650          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
651                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
652          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
653                  if ( $item == ".." || $item == "." ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
654                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
655                          $dirList[] = $item ;                          $dirList[] = $item ;
656                  }                  } else if ( is_file($fsDir . $item) ) {
                 else if ( is_file($fsDir . $item) ) {  
657                          $fileList[] = $item ;                                    $fileList[] = $item ;          
658                  }                  } else if ( is_link($fsDir . $item) ) {
659                  else {                          $dirList[] = $item ;
660                    } else {
661                    // unknown file type                    // unknown file type
662                    // $text = "Could not determine file type of " ;                    // $text = "Could not determine file type of " ;
663                    // Error("File Error", $text.$relDir."/".$item) ;                    // Error("File Error", $text.$relDir."/".$item) ;
# Line 510  function Navigate($fsRoot,$relDir) { Line 665  function Navigate($fsRoot,$relDir) {
665                  }                  }
666          }          }
667          closedir($dir) ;          closedir($dir) ;
668    
669            // scan deleted files
670            if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
671                    while ($item = readdir($dir)) {
672                            if ( substr($item,0,1) == "." ) continue ;
673                            $fileList[] = ".del/$item" ;            
674                    }
675                    closedir($dir) ;
676            }
677    
678          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
679    
680          // start navigation page          // start navigation page
681          $text  = "Use this page to add, delete or " ;          $text  = "Use this page to add, delete";
682          $text .= "revise files on this web site." ;          if (! isset($show_deleted)) {
683                    $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
684            }
685            $text .= " or revise files on this web site." ;
686            $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>.";
687          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
688    
689          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 527  function Navigate($fsRoot,$relDir) { Line 695  function Navigate($fsRoot,$relDir) {
695                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
696  ?>  ?>
697    
698  <TR><TD><?php echo $gblIcon("up") ?></TD><TD COLSPAN=4 CLASS=LST>  <TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST>
699  <A HREF="<?php echo $self ?>?D=<?php echo urlencode($parent) ?>">  <A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>">
700  <B><?php echo $parent ?></B></A></TD></TR>  <B><?= $parent ?></B></A></TD></TR>
701    
702  <?php  <?php
703          }          }
704    
705    function plural($name,$count) {
706            $out="$count $name";
707            if ($count > 1) {
708                    $out.="s";
709            }
710            return $out;
711    }
712    
713          // output subdirs          // output subdirs
714          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
715                  sort($dirList) ;                  sort($dirList) ;
716  ?>  ?>
717    
718  <TR><TD></TD><TD COLSPAN=4 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>  <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME (<?= plural("dir",sizeof($dirList)) ?>)</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>
719    
720  <?php  <?php
721                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
722    
723                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
724                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
725                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
726                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
727                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
728  ?>  ?>
729    
730  <TR><TD><?php echo $gblIcon("fldr") ?></TD>  <TR><TD>
731  <TD COLSPAN=4 CLASS=LST><?php echo $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
732    <?= $gblIcon("fldr") ?></A></TD>
733    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
734    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
735    
736  <?php  <?php
737                  }  // iterate over dirs                  }  // iterate over dirs
738          }  // end if no dirs          }  // end if no dirs
739  ?>  ?>
740    
741  <TR><TD></TD><TD COLSPAN=4><HR><B><?php echo $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
742  </B></TD></TR>  </B></TD></TR>
743  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
744  <TD><?php echo $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
745    <TD CLASS=TOP>NOTE</TD>
746  <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>
747    
748  <?php  <?php
749          if (sizeof($fileList) > 0) {          if (sizeof($fileList) > 0) {
750            sort($fileList) ;            sort($fileList) ;
751            while (list($key,$file) = each($fileList)) {              while (list($key,$file) = each($fileList)) {  
752              $path = $fsDir."/".$file ;                  $path = $fsDir."/".$file ;
753              $mod  = filemtime($path) ;                  $mod  = filemtime($path) ;
754              $sz   = filesize($path) ;                  $sz   = filesize($path) ;
755    
756              if ($sz >= 10240) {                  if ($sz >= 10240) {
757                $sz = (int)(($sz+1023)/1024) . " k" ;                          $sz = (int)(($sz+1023)/1024) . " k" ;
758              }                  } else {
759              else {                          $sz .= " " ;
760                $sz .= " " ;                  } // end size
761              } // end size  
762                    $a = $b = "" ;
763              $a = $b = "" ;  
764                    $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
765              if ( ($mod + 30*86400) > time() ) {  
766                $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                  if ( ($mod + $gblModDays*86400) > time() ) {
767                $a .= " than 30 days\"> * </SPAN>" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
768              }                          $a .= " than $gblModDays days\"> * </SPAN>" ;
769                    }
770              $tstr = $webRoot . $relDir . "/" . $file ;  
771              $tstr  = "<A HREF=\"" . $tstr . "\">" ;                  $file_lock=CheckLock($path);
772              $tstr .= $file . "</A>" . $a ;  
773                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
774              $ext = strtolower(strrchr($file,".")) ;                  $file_url_html.="&D=".urlencode($relDir);
775              if ( $ext=="" ||                  $file_url_html.="\" TITLE=\"View file\">" ;
776                   strstr(join(" ",$gblEditable),$ext) )  
777              {                    if (substr($file,0,5) != ".del/") {
778                $b  = "<A HREF=\"" . $self . "?A=C&F=" ;                          $file_url_html .= $file . "</A>" . $a ;
779                $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                  } else {
780                $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>";
781                $b .= $gblIcon("view") . "</A>" ;                  }
782              }  
783                    $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
784    
785                    $ext = strtolower(strrchr($file,".")) ;
786    
787                    if ($file_lock) {
788                            if ($file_lock == $GLOBALS[gblUserName]) {
789                                    $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
790                                    $b.="&D=".urlencode($relDir);
791                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
792                                    $file_url_html=$b;
793                                    $b.=$gblIcon("checkin")."</A>" ;
794                                    $b.= $gblIcon("blank");
795                                    $file_url_html.="$file</a> $a";
796                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
797                            } else {
798                                    $b = $gblIcon("locked");
799                                    $b.= $gblIcon("blank");
800                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
801                                    $file_url_html = "$file $a";
802                            }
803                    } else {
804                            $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
805                            $b.="&D=".urlencode($relDir);
806                            $b.="\" TITLE=\"Checkout file for edit\">" ;
807                            $b.=$gblIcon("checkout")."</A>" ;
808    
809                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
810                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
811                                    $b.="&D=".urlencode($relDir);
812                                    $b.="\" TITLE=\"List contents\">" ;
813                                    $b.=$gblIcon("view")."</A>" ;
814                            } else {
815                                    $b.= $gblIcon("blank");
816                            }
817                    }
818    
819    
820  ?>  ?>
821    
822  <TR><TD>  <TR><TD>
823  <A HREF="<?php echo $self ?>?A=E&F=<?php echo urlencode($file)  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
824  ?>&D=<?php echo urlencode($relDir) ?>" TITLE="View/Edit">  <?= $gblIcon($ext) ?></A></TD>
825  <?php echo $gblIcon($ext) ?></A></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
826  <TD CLASS=LST><?php echo $tstr ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
827  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
828  <TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
829  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
830    
831  <?php  <?php
832            }  // iterate over files            }  // iterate over files
833          }  // end if no files          } else {  // end if no files
834    ?>
835     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
836      No files in this directory
837     </TD></TR>
838    <?
839            }
840    
841          if ($emptyDir) {          if ($emptyDir) {
842  ?>  ?>
843    
844  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
845   <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>   <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
846    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
847    OK TO DELETE THIS EMPTY FOLDER?    OK TO DELETE THIS EMPTY FOLDER?
848    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
849    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
# Line 630  function Navigate($fsRoot,$relDir) { Line 854  function Navigate($fsRoot,$relDir) {
854          } // end if emptyDir          } // end if emptyDir
855  ?>  ?>
856    
857  <TR><TD></TD><TD COLSPAN=4><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
858    
859  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <?
860  <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>CREATE NEW  if (file_exists(".info.inc")) {
861            print "<TR><TD></TD><TD COLSPAN=5>";
862            include(".info.inc");
863            print "</TD></TR>
864            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
865    }
866    ?>
867    
868    <FORM METHOD="POST" ACTION="<?= $self ?>">
869    <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
870   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
871   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
872   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
873   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
874   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
875   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
876   <NOBR>OR <A HREF="<?php echo $self   </NOBR>
877          ?>?A=U&D=<?php echo urlencode($relDir) ?>">UPLOAD</A> A FILE   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
878   </NOBR>   </NOBR>
879  </TD></TR>  </TD></TR>
880  </FORM>  </FORM>
# Line 653  function Navigate($fsRoot,$relDir) { Line 886  function Navigate($fsRoot,$relDir) {
886    
887  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
888    
889  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename="") {
890    
891          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
892          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 661  function UploadPage($fsRoot, $relDir) { Line 894  function UploadPage($fsRoot, $relDir) {
894    
895  <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>
896  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
897   ACTION="<?php echo $self ?>">   ACTION="<?= $self ?>">
898  DESTINATION DIRECTORY:<B><?php echo " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
899    <? if (isset($filename) && $filename!="") { ?>
900    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
901    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
902    <? } ?>
903  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
904  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
905  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
906  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
907  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
908  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
909  you must upgrade to an RFC1867-compliant browser.</P>  you must upgrade to an RFC1867-compliant browser.</P>
910  <P>Your browser:<BR><?php echo $GLOBALS["HTTP_USER_AGENT"] ?></P>  <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
911  </FORM>  </FORM>
912  </TD></TR>  </TD></TR>
913  <TR><TD></TD><TD>  <TR><TD></TD><TD>
914  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
915  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>"><BR>  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
916  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
917  </FORM>  </FORM>
918  </TD></TR></TABLE></P>  </TD></TR></TABLE></P>
# Line 694  function Error($title,$text="") { Line 931  function Error($title,$text="") {
931    
932  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
933    
934  function Writeable($path) {  function NoEntry() {
         // fix by -mat- filid brandy, brandy@ecrc.de, 07/JUL/99  
935    
936          clearstatcache ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
937          $perms = @fileperms($path) ;          $pw   = $GLOBALS["PHP_AUTH_PW"] ;      
938          $owner = @fileowner($path) ;          $self = $GLOBALS["PHP_SELF"] ;
         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  
939    
940  //////////////////////////////////////////////////////////////////          $title = "(401 Unauthorized)" ;
941            $text  = "No trespassing !" ;
942            StartHTML($title,$text) ;
943    
 function CreateHash($user, $pw) {  
   
         global $gblHash ;  // hash function to use  
   
         if ($user == "" || $pw == "") {  
                 $text = "either no password or no username supplied" ;  
                 Error("Create Hash",$text) ;  
         }  
         $title = "(Create Hash)" ;  
         StartHTML($title) ;  
         echo "<P ALIGN=center>" ;  
         echo "<BLOCKQUOTE>Copy the value below and paste it " ;  
         echo "into the<BR>value for \$gblPw in the source of " ;  
         echo "this file<BR><BR><B>" . $gblHash($user.$pw) ;  
         echo "</B><BR><BR>Hash function: " . $gblHash ;  
         echo "</BLOCKQUOTE></P>" ;  
944          EndHTML() ;          EndHTML() ;
945          exit ;          exit ;
946    }
947    
948    //////////////////////////////////////////////////////////////////
949    
950    function LogIt($target,$msg) {
951    
952            $dir=dirname($target);
953            if (! file_exists($dir."/.log")) {
954                    mkdir($dir."/.log",0700);
955            }
956            $file=basename($target);
957    
958            $log=fopen("$dir/.log/$file","a+");
959            fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
960                    "\t$GLOBALS[gblUserName]\t$msg\n");
961            fclose($log);
962    
963    }
964    
 } // end function CreateHash  
965    
966  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
967    
968  function NoEntry() {  function WriteNote($target,$msg) {
969    
970          $user = $GLOBALS["PHP_AUTH_USER"] ;          $target=stripSlashes($target);
971          $pw   = $GLOBALS["PHP_AUTH_PW"] ;                $dir=dirname($target);
972          $self = $GLOBALS["PHP_SELF"] ;          if (! file_exists($dir."/.note")) {
973                    mkdir($dir."/.note",0700);
974            }
975            $file=basename($target);
976    
977          $title = "(401 Unauthorized)" ;          $note=fopen("$dir/.note/$file","w");
978          $text  = "No trespassing !" ;          fputs($note,"$msg\n");
979          StartHTML($title,$text) ;          fclose($note);
 ?>  
980    
981  <FORM ACTION="<?php echo $self ?>?HASH=create" METHOD="POST">          Logit($target,"added note $msg");
982  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?php echo $user ?>">  
983  <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?php echo $pw ?>">  }
984    
985  <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>  function ReadNote($target) {
986  Click below to <B>generate a password hash</B><BR>from  
987  the username-password pair you just<BR>entered. Then include the hash in          $target=stripSlashes($target);
988  the source<BR>of this file.<BR><BR>          $dir=dirname($target);
989  <INPUT TYPE="SUBMIT" VALUE="CREATE HASH">          $file=basename($target);
990  </BLOCKQUOTE></FORM>          $msg="";
991            if (file_exists($dir."/.note/$file")) {
992                    $note=fopen("$dir/.note/$file","r");
993                    $msg=fgets($note,4096);
994                    fclose($note);
995            }
996            return HtmlSpecialChars(StripSlashes($msg));
997    
998    }
999    
1000    //////////////////////////////////////////////////////////////////
1001    
1002    function MoveTo($source,$folder) {
1003    
1004            $source=stripSlashes($source);
1005            $file=basename($source);
1006            if (! file_exists($folder)) {
1007                    mkdir($folder,0700);
1008            }
1009            if (file_exists($source)) {
1010                    rename($source,"$folder/$file");
1011            }
1012    }
1013    
1014    //////////////////////////////////////////////////////////////////
1015    
1016    function Lock($target) {
1017    
1018            $target=stripSlashes($target);
1019            $dir=dirname($target);
1020            if (! file_exists($dir."/.lock")) {
1021                    mkdir($dir."/.lock",0700);
1022            }
1023            $file=basename($target);
1024    
1025            if (file_exists("$dir/.lock/$file")) {
1026                    Logit($target,"attempt to locked allready locked file!");
1027            } else {
1028                    $lock=fopen("$dir/.lock/$file","w");
1029                    fputs($lock,"$GLOBALS[gblUserName]\n");
1030                    fclose($lock);
1031    
1032                    Logit($target,"file locked");
1033            }
1034    
1035    }
1036    
1037    function CheckLock($target) {
1038    
1039            $target=stripSlashes($target);
1040            $dir=dirname($target);
1041            $file=basename($target);
1042            $msg=0;
1043            if (file_exists($dir."/.lock/$file")) {
1044                    $lock=fopen("$dir/.lock/$file","r");
1045                    $msg=fgets($lock,4096);
1046                    fclose($lock);
1047            }
1048            return chop($msg);
1049    
1050    }
1051    
1052    function Unlock($target) {
1053    
1054            $target=stripSlashes($target);
1055            $dir=dirname($target);
1056            $file=basename($target);
1057            if (file_exists($dir."/.lock/$file")) {
1058                    unlink("$dir/.lock/$file");
1059                    Logit($target,"file unlocked");
1060            } else {
1061                    Logit($target,"attempt to unlocked non-locked file!");
1062            }
1063    
1064  <?php  }
1065          EndHTML() ;  
1066          exit ;  //////////////////////////////////////////////////////////////////
1067    
1068    function urlpath($url) {
1069            $url=urlencode(StripSlashes("$url"));
1070            $url=str_replace("%2F","/",$url);
1071            $url=str_replace("+","%20",$url);
1072            return($url);
1073    }
1074    
1075    //////////////////////////////////////////////////////////////////
1076    
1077    function safe_rename($fromdir,$fromfile,$tofile) {
1078            function try_rename($from,$to) {
1079    #               print "$from -> $to\n";
1080                    if (file_exists($from) && is_writeable(dirname($to))) {
1081                            rename($from,$to);
1082                    }
1083            }
1084    
1085            function try_dir($todir) {
1086                    if (! file_exists($todir)) {
1087                            mkdir($todir,0700);
1088                    }
1089            }
1090    
1091            $to="$fromdir/$tofile";
1092            $todir=dirname($to);
1093            $tofile=basename($to);
1094    
1095    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1096    
1097            try_rename("$fromdir/$fromfile","$todir/$tofile");
1098            try_dir("$todir/.log");
1099            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1100            try_dir("$todir/.note");
1101            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1102            try_dir("$todir/.lock");
1103            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1104            try_dir("$todir/.bak");
1105            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1106                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1107            }
1108    }
1109    
1110    
1111    //////////////////////////////////////////////////////////////////
1112    
1113    // recursivly delete directory
1114    
1115    function rrmdir($dir) {
1116            $handle=opendir($dir);
1117            while ($file = readdir($handle)) {
1118                    if ($file != "." && $file != "..") {
1119                            if (is_dir("$dir/$file"))
1120                                    rrmdir("$dir/$file");
1121                            else
1122                                    if (! @unlink("$dir/$file")) return(0);
1123                    }
1124            }
1125            closedir($handle);
1126            return @rmdir($dir);
1127    }
1128    
1129    //////////////////////////////////////////////////////////////////
1130    
1131    function ChangeLog($target,$msg) {
1132    
1133            global $gblFsRoot;
1134            $log=fopen("$gblFsRoot/.changelog","a+");
1135            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1136                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1137            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1138            fclose($log);
1139    
1140    }
1141    
1142    function DisplayChangeLog($day) {
1143    
1144            global $gblFsRoot;
1145            if (!file_exists("$gblFsRoot/.changelog")) return;
1146            $log=fopen("$gblFsRoot/.changelog","r");
1147            $logarr = array();
1148            while($line = fgetcsv($log,255,"\t")) {
1149                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1150                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1151                    }
1152            }
1153            fclose($log);
1154            $cl1=" class=LST"; $cl2="";
1155            print "<table border=0 width=100%>\n";
1156            while ($e = array_shift($logarr)) {
1157                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1158                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1159                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1160                    $dir = dirname($e[1]);
1161                    $file = basename($e[1]);
1162                    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";
1163            }
1164            print "</table>";
1165            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1166  }  }
1167    
1168  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 773  the source<BR>of this file.<BR><BR> Line 1173  the source<BR>of this file.<BR><BR>
1173  // local functions : begin with capital letters  // local functions : begin with capital letters
1174  // global constants: begin with gbl  // global constants: begin with gbl
1175    
1176          $gblFilePerms = "644" ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1177          $gblDirPerms  = 0755 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1178    
1179          // phpinfo() ;          // phpinfo() ;
1180          // exit ;          // exit ;
# Line 782  the source<BR>of this file.<BR><BR> Line 1182  the source<BR>of this file.<BR><BR>
1182          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1183          // creation if password not yet set.          // creation if password not yet set.
1184          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1185          if ($HASH != "") {  
1186                  CreateHash($USER, $PW) ;          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1187                  exit ;          // i.e. /home/httpd/html/docman
1188    
1189            // read user-defined configuration
1190            if (file_exists("$fsScriptDir/.docman.conf")) {
1191                    include("$fsScriptDir/.docman.conf");
1192          }          }
1193    
1194          // authentication if $gblAuth == true          // where do we get users from?
1195          if ( $gblAuth &&          if (file_exists("$gblIncDir/$gblUsers.php")) {
1196               $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) {                  include("$gblIncDir/$gblUsers.php");
1197                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;          } else {
1198                    Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>");
1199            }
1200    
1201            // authentication failure
1202            if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1203                    isset($relogin) && $gblPw == $relogin ) {
1204                    header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1205                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1206                  NoEntry() ;                  NoEntry() ;
1207                  exit ;                  exit ;
# Line 802  the source<BR>of this file.<BR><BR> Line 1213  the source<BR>of this file.<BR><BR>
1213                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1214          }                }      
1215    
1216            $relDir=stripSlashes($relDir);
1217    
1218          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1219          // default : website root = ""          // default : website root = ""
1220    
# Line 813  the source<BR>of this file.<BR><BR> Line 1226  the source<BR>of this file.<BR><BR>
1226          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1227    
1228          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1229          // i.e. /siteman          // i.e. /docman
1230    
1231          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              // start on server root
1232          // i.e. /home/httpd/html/siteman  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1233            // or on script root
1234          $gblFsRoot = substr($fsScriptDir,0,          $gblFsRoot = $fsScriptDir;
           strlen($fsScriptDir)-strlen($relScriptDir)) ;  
1235          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1236    
1237          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1238          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1239            
1240            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1241                    $webRoot  = "https://";
1242            } else {
1243                    $webRoot  = "http://";
1244            }
1245            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1246    
1247            $FN=stripSlashes($FN);
1248    
1249    
1250          switch ($POSTACTION) {          switch ($POSTACTION) {
1251          case "UPLOAD" :          case "UPLOAD" :
1252                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1253                  if (strstr($FN_name,"/"))                  if (strstr($FN_name,"/"))
1254                          Error("Non-conforming filename") ;                          Error("Non-conforming filename") ;
1255                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1256                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1257                  $source = $FN ;                  $source = $FN ;
1258                  $target = $fsDir . "/" . $FN_name ;                  if (! file_exists($source)) {
1259                  exec("cp $source $target") ;                          Error("You must select file with browse to upload it!");
1260                  exec("chmod $gblFilePerms $target") ;                  }
1261                    if (! isset($FILENAME)) {       // from update file
1262                            $target = "$fsDir/$FN_name" ;
1263                    } else {
1264                            $target = "$fsDir/$FILENAME";
1265                    }
1266    
1267                    // backup old files first
1268                    $dir=dirname($target);
1269                    if (! file_exists($dir."/.bak")) {
1270                            mkdir($dir."/.bak",0700);
1271                    }
1272                    if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
1273                            mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
1274                    }
1275                    $file=basename($target);
1276                    for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1277                            MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1278                    }
1279                    MoveTo($target,$dir."/.bak/1/");
1280    
1281                    copy($source,$target) ;
1282                    chmod($target,$gblFilePerms) ;
1283                  clearstatcache() ;                  clearstatcache() ;
1284                    Logit($target,"uploaded");
1285                    if (isset($FILENAME)) {
1286                            Unlock($target);
1287                    }
1288                    ChangeLog($target,"updated");
1289                  break ;                  break ;
1290    
1291          case "SAVE" :          case "SAVE" :
1292                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1293                  $writable = Writeable($path) ;                  $path=stripSlashes($path);
1294                  $legaldir = Writeable(dirname($path)) ;                  $writable = is_writeable($path) ;
1295                    $legaldir = is_writeable(dirname($path)) ;
1296                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1297  // check for legal extension here as well  // check for legal extension here as well
1298                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1299                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1300                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1301                    $FILEDATA=stripSlashes($FILEDATA);
1302                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1303                  fclose($fh) ;                  fclose($fh) ;
1304                  clearstatcache() ;                  clearstatcache() ;
1305                    Logit($path,"saved changes");
1306                    ChangeLog($path,"saved changes");
1307                  break ;                  break ;
1308    
1309          case "CREATE" :          case "CREATE" :
1310                  // we know $fsDir exists                  // we know $fsDir exists
1311                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if ($FN == "") break;           // no filename!
1312                    if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1313                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = $fsDir . "/" . $FN ;  // file or dir to create
1314                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1315                  switch ( $T ) {                  switch ( $T ) {
1316                  case "D" :  // create a directory                  case "D" :  // create a directory
1317                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1318                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1319                    clearstatcache() ;                          clearstatcache() ;
1320                    break ;                          break ;
1321                  case "F" :  // create a new file                  case "F" :  // create a new file
1322  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1323  // better keep it here altogether  // better keep it here altogether
1324  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1325                    if ( file_exists($path) && !Writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1326                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1327                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1328                    header("Location: " . $tstr) ;                          if ($fh) {
1329                    exit ;                                  fputs($fh,"\n");
1330                                    fclose($fh) ;
1331                                    LogIt($path,"file created");
1332                            } else {
1333                                    Error("Creation of file $relPath failed -- $path");
1334                            }
1335                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1336                            header("Location: " . $tstr) ;
1337                            ChangeLog($target,"created");
1338                            exit ;
1339                  }                  }
1340                  break ;                  break ;
1341    
# Line 883  the source<BR>of this file.<BR><BR> Line 1346  the source<BR>of this file.<BR><BR>
1346                  $tstr .= "insufficient privileges: " ;                  $tstr .= "insufficient privileges: " ;
1347    
1348                  if ( $FN != "") {  // delete file                  if ( $FN != "") {  // delete file
1349                    $path =  $fsDir . "/" . $FN ;                          $path =  $fsDir . "/" . $FN ;
1350                    if ( ! @unlink($path) ) {                  
1351                      Error("File delete failed", $tstr . $path) ;                          $dir=dirname($path);
1352                      exit ;                          $file=basename($path);
1353                    }                                              if (! file_exists("$dir/.del")) {
1354                                    mkdir("$dir/.del",0700);
1355                            }
1356    
1357    //                      if ( ! @unlink($path) ) {
1358                            if ( ! rename($path,"$dir/.del/$file") ) {
1359                                    Error("File delete failed", $tstr . $path) ;
1360                                    Logit($path,"file delete failed");
1361                                    exit ;
1362                            } else {
1363                                    Logit($path,"file deleted");
1364                                    MoveTo("$dir/.log/$file","$dir/.del/.log/");
1365                                    MoveTo("$dir/.note/$file","$dir/.del/.note/");
1366                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1367                            }
1368                  }                  }
1369                  else {  // delete directory                  else {  // delete directory
1370                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1371                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1372                    }                    }
1373                    else {                    else {
# Line 899  the source<BR>of this file.<BR><BR> Line 1376  the source<BR>of this file.<BR><BR>
1376                  }                  }
1377                  break ;                  break ;
1378    
1379            case "UNDELETE" :  
1380                    if ( $CONFIRM != "on" ) break ;
1381    
1382                    if (substr($FN,0,4) != ".del") break ;
1383                    $file=substr($FN,4,strlen($FN)-4);
1384    
1385                    Logit("$fsDir/.del/$file","undeleted");
1386                    MoveTo("$fsDir/.del/$file","$fsDir/");
1387                    MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1388                    MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1389                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1390    
1391                    break ;
1392    
1393            case "RENAME" :  
1394                    if ( $CONFIRM != "on" ) break ;
1395    
1396                    Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1397                    safe_rename($fsDir,$FN,$NEWNAME);
1398                    break ;
1399    
1400            case "NOTE" :  
1401                    WriteNote("$fsDir/$FN","$NOTE");
1402                    break ;
1403    
1404            case "UNLOCK" :  
1405                    if ( $CONFIRM != "on" ) break ;
1406                    Unlock("$fsDir/$FN");
1407                    break ;
1408    
1409          default :          default :
1410                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1411          }          }
# Line 914  the source<BR>of this file.<BR><BR> Line 1421  the source<BR>of this file.<BR><BR>
1421          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1422          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1423          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1424            // $A=Co : checkout file $D/$F
1425            // $A=Ci : checkin file $D/$F
1426            // $A=V : view file (do nothing except log)
1427          // default : display directory $D          // default : display directory $D
1428            
1429          switch ($A) {          switch ($A) {
1430          case "U" :          case "U" :
1431                  // upload to $relDir                  // upload to $relDir
1432                  if (!Writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1433                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1434                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1435                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1436                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1437                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1438                  EndHTML() ;                  EndHTML() ;
1439                  exit ;                  exit ;
1440          case "E" :          case "E" :
1441                    $F=stripSlashes($F);
1442                  // detail of $relDir/$F                  // detail of $relDir/$F
1443                  DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1444                  exit ;                  exit ;
1445          case "C" :          case "C" :
1446                    $F=stripSlashes($F);
1447                  // listing of $relDir/$F                  // listing of $relDir/$F
1448                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1449                  exit ;                  exit ;
1450            case "Co" :
1451                    // checkout
1452                    Lock("$gblFsRoot/$relDir/$F");
1453                    header("Content-Disposition: attachment; filename=$F" );
1454                    Header("Location: $webRoot".urlpath("$relDir/$F"));
1455                    exit;
1456            case "Ci" :
1457                    $F=stripSlashes($F);
1458                    // upload && update to $relDir
1459                    if (!is_writeable($gblFsRoot . $relDir))
1460                            Error("Write access denied",$relDir) ;
1461                    $text  = "Use this page to update a single " ;
1462                    $text .= "file to <B>$HTTP_HOST</B>." ;
1463                    StartHTML("(Update file Page)", $text) ;
1464                    UploadPage($gblFsRoot, $relDir, $F) ;
1465                    EndHTML() ;
1466                    exit ;
1467            case "V" :
1468                    // view
1469                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1470                    header("Content-Disposition: attachment; filename=$F" );
1471                    Header("Location: $webRoot".urlpath("$relDir/$F"));
1472                    exit;
1473            case "Ch" :
1474                    StartHTML("(File changes)","All changes chronologicaly...");
1475                    DisplayChangeLog(0);    // all
1476                    EndHTML() ;
1477                    exit;
1478            case "Ch1" :
1479                    StartHTML("(File changes)","Changes to files in last day...");
1480                    DisplayChangeLog(1);
1481                    EndHTML() ;
1482                    exit;
1483          }          }
1484    
1485          // default: display directory $relDir          // default: display directory $relDir

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

  ViewVC Help
Powered by ViewVC 1.1.26