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

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

  ViewVC Help
Powered by ViewVC 1.1.26