/[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.3 by dpavlin, Thu Aug 3 19:35:44 2000 UTC revision 1.40 by dpavlin, Fri Apr 6 08:46:42 2001 UTC
# Line 35  Line 35 
35  /*             existent address after file modifications.       */  /*             existent address after file modifications.       */
36    
37  /*  /*
         2000-07-25 Dobrica Pavlinusic <dpavlin@rot13.org>  
38    
39          nuked exec calls (unsecure)          This project is now called Directory Manager.
         nuked writeable function (replaced by php is_writeable)  
         added support for https (tested with apache+mod_ssl)  
         added users file  
         date format user-selectable  
         cycle backup files in bak directory  
         support links as directoryes (for now)  
         support of file history logging  
         undelete capabilities (delete moves to .del directory)  
40    
41          2000-07-26 DbP          For more info, please see web pages at
42            http://www.rot13.org/~dpavlin/docman.html
43    
44          added more checking on entered filename (when creating file/dir)          It's relased under GPL by
45          added rename option          Dobrica Pavlinusic <dpavlin@rot13.org>
46    
47    
48  IMPORTANT INSTALLATION NOTE:  IMPORTANT INSTALLATION NOTE:
# Line 59  IMPORTANT INSTALLATION NOTE: Line 51  IMPORTANT INSTALLATION NOTE:
51          deleted files!          deleted files!
52    
53          .htusers is in form:          .htusers is in form:
54          login:Real Name:md5(loginpassword)          login:Real Name:[md5(loginpassword)|auth_*]:email@host.dom
55    
56    
57  TODO:  TODO:
58          mixed file/directory output (add type to each entry,          mixed file/directory output (add type to each entry,
59                  real support for links)                  real support for links)
60          add more content-management (like cms.sourceforge.net):          access controll
61                  check-out/check-in/reserve  
                 comments to files  
62  */  */
63    
64  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 80  TODO: Line 71  TODO:
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    
 //      $gblPw    = "hash_of_your_username_and_password" ;  
   
 //      $gblAuth  = false ;             // use builtin authentication  
         $gblAuth  = true ;             // use builtin authentication  
         $gblHash  = "md5" ;             // hash function to use  
   
84          $gblPw    = "";          $gblPw    = "";
85    
86          if ($gblAuth) {          // date format
                 $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";  
                 if (! file_exists($htusers_file)) {  
                         $htusers=fopen($htusers_file,"a+");  
                         fputs($htusers,"# Change owner of $htusers_file to root !!\n");  
                         fputs($htusers,"demo:full name:md5_hash\n");  
                         fclose($htusers);  
                 }  
                 $htusers=fopen($htusers_file,"r");  
                 while($user = fgetcsv($htusers,255,":")) {  
                         if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {  
                                 $gblUserName=$user[1];  
                                 $gblPw=$user[2];  
                                 continue ;  
                         }  
                 }  
                 fclose($htusers);  
         }  
   
87  //      $gblDateFmt="D, F d, Y";  //      $gblDateFmt="D, F d, Y";
 //      $gblTimeFmt="g:i:sA";  
   
88          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
89    
90            // time format
91    //      $gblTimeFmt="g:i:sA";
92          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
93    
94  // Number of backup files to keep          // Number of backup files to keep
95          $gblNumBackups=5;          $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 150  TODO: Line 124  TODO:
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 184  function EndHTML() { Line 158  function EndHTML() {
158  <B><?= date($GLOBALS[gblDateFmt]) ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
159  <?= date($GLOBALS[gblTimeFmt]) ?> -  <?= date($GLOBALS[gblTimeFmt]) ?> -
160  <?= $GLOBALS[gblUserName] ?>  <?= $GLOBALS[gblUserName] ?>
161  <small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>  <small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>
162  </B>  </B>
163  <BR>ANYPORTAL(php) Site Manager  <BR>ANYPORTAL(php) Site Manager
164  <br><small>  <br><small>
# Line 194  function EndHTML() { Line 168  function EndHTML() {
168  </small>  </small>
169  </P>  </P>
170  <BR>  <BR>
171  <? //include("../debug.inc") ?>  <? //include(".debug.inc") ?>
172  <BR><BR></BODY></HTML>  <BR><BR></BODY></HTML>
173    
174  <?php  <?php
# Line 229  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 240  function DetailPage($fsRoot,$relDir,$fn) Line 214  function DetailPage($fsRoot,$relDir,$fn)
214          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
215          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
216          $writable = is_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) ;
# Line 247  function DetailPage($fsRoot,$relDir,$fn) Line 222  function DetailPage($fsRoot,$relDir,$fn)
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("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
238            $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
239            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
240            echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  $fgid=filegroup($fsPath);
241            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  $userinfo = posix_getpwuid($fuid);
242            echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  $grpinfo = posix_getgrgid($fgid);
243            echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "<PRE>";
244            echo "  permissions: <B>" ;                  if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
245            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
246            echo "</PRE>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
247                    echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
248                    echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
249                    echo "  permissions: <B>" ;
250                    echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
251                    echo "</PRE>" ;
252    
253          }          }
254    
255          if ( $editable && ($writable || !$exists) ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
256                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
257                  rewind($fh) ;                  rewind($fh) ;
258                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 276  function DetailPage($fsRoot,$relDir,$fn) Line 260  function DetailPage($fsRoot,$relDir,$fn)
260                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
261  ?>  ?>
262    
263  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
264  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
265          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
266  </SPAN><BR>  </SPAN><BR>
267  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
268  echo($fstr) ; ?></TEXTAREA>  echo($fstr) ; ?></TEXTAREA>
269  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
270  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
271  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
272  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
273          VALUE="<?php echo $relPath ; ?>">          VALUE="<?= $relPath ; ?>">
274  <br>  <br>
275  <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">  <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
276  <INPUT TYPE="SUBMIT" VALUE="SAVE">  <INPUT TYPE="SUBMIT" VALUE="SAVE">
# Line 294  echo($fstr) ; ?></TEXTAREA> Line 278  echo($fstr) ; ?></TEXTAREA>
278    
279  <?php  <?php
280          }          }
281          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
282            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
283            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
284            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
285            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
286            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
287                    echo $tstr ;
288          }          }
289    
290  ?>  ?>
291    
292  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
293  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
294  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
295  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
296    
297  <?php  <?php
298    
299            if ($file_lock) {
300    ?>
301    <hr>
302    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
303    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
304    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
305    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
306    <?
307            } // file_lock
308    
309          if (substr($fn,0,4) == ".del") {          if (substr($fn,0,4) == ".del") {
310                  $action="UNDELETE";                  $action="UNDELETE";
311                  $desc="undelete previously deleted file";                  $desc="undelete previously deleted file";
# Line 320  echo($fstr) ; ?></TEXTAREA> Line 317  echo($fstr) ; ?></TEXTAREA>
317          if ($exists && $writable) {          if ($exists && $writable) {
318  ?>  ?>
319    
320  <HR><SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">  <HR>
321  <B>OK TO <?= $action ?> "<?php echo $fn ; ?>"? </B></SPAN>  <a name="undelete">
322    <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
323    <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>
324  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
325  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
326    
327  <HR><SPAN TITLE="Check OK and click [RENAME] to rename.">  <HR>
328  <B>OK TO RENAME "<?php echo $fn ; ?>" TO  <a name="rename">
329    <SPAN TITLE="Check OK and click [RENAME] to rename.">
330    <B>OK TO RENAME "<?= $fn ; ?>" TO
331  <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">  <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
332  ? </B></SPAN>  ? </B></SPAN>
333  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
334  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
335    
336  <?php  <?php
337          }          }       // exists && writable
338          echo "</FORM>" ;  ?>
339    <HR>
340    <a name="note">
341    <B>NOTE FOR "<?= $fn ; ?>":
342    <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">
343    </B></SPAN>
344    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
345    
346    </FORM>
347    
348          $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn");  <?php
349    
350            $name=basename("$fsDir/$fn");
351            $logname=dirname("$fsDir/$fn")."/.log/$name";
352            $bakdir=dirname("$fsDir/$fn")."/.bak";
353          if (file_exists($logname)) {          if (file_exists($logname)) {
                 print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";  
354                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
355                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
356                    $logarr = array();
357                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
358                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
359                          print "<tr><td$cl>$line[0]</td><td$cl>$line[1]</td><td$cl>$line[2]</td><td$cl>$line[3]</td></tr>\n";                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
360                  }                  }
361                  fclose($log);                  fclose($log);
362                    if (is_dir("$fsDir/$fn")) {
363                            $whatis="DIRECTORY";
364                    } else {
365                            $whatis="FILE";
366                    }
367                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
368                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
369                    while ($e = array_shift($logarr)) {
370                            if (strstr($e[4],"upload")) {
371                                    if (file_exists("$bakdir/$bakcount/$name")) {
372                                            $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
373                                    }
374                                    $bakcount++;
375                            }
376                            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";
377                    }
378                  print "</table>";                  print "</table>";
379          }          }
380    
# Line 578  function GifIcon($txt) { Line 607  function GifIcon($txt) {
607          case "blank" :          case "blank" :
608                  $d = "blank.gif" ;                  $d = "blank.gif" ;
609                  break ;                  break ;
610            case "checkout":
611                    $d = "box2.gif";
612                    break;
613            case "checkin":
614                    $d = "hand.up.gif";
615                    break;
616            case "locked":
617                    $d = "screw2.gif";
618                    break;
619            case "note":
620                    $d = "quill.gif";
621                    break;
622          default :          default :
623                  $d = "generic.gif" ;                  $d = "generic.gif" ;
624          }          }
# Line 589  function GifIcon($txt) { Line 630  function GifIcon($txt) {
630    
631  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
632    
633          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot ;
634    
635          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
636          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
637                  $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
638    
639          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
640    
# Line 635  function Navigate($fsRoot,$relDir) { Line 672  function Navigate($fsRoot,$relDir) {
672          // start navigation page          // start navigation page
673          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
674          if (! isset($show_deleted)) {          if (! isset($show_deleted)) {
675                  $text .= ", <a href=".$GLOBALS[PHP_SELF]."?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
676          }          }
677          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
678            $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>.";
679          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
680    
681          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 649  function Navigate($fsRoot,$relDir) { Line 687  function Navigate($fsRoot,$relDir) {
687                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
688  ?>  ?>
689    
690  <TR><TD><?php echo $gblIcon("up") ?></TD><TD COLSPAN=4 CLASS=LST>  <TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST>
691  <A HREF="<?php echo $self ?>?D=<?php echo urlencode($parent) ?>">  <A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>">
692  <B><?php echo $parent ?></B></A></TD></TR>  <B><?= $parent ?></B></A></TD></TR>
693    
694  <?php  <?php
695          }          }
# Line 661  function Navigate($fsRoot,$relDir) { Line 699  function Navigate($fsRoot,$relDir) {
699                  sort($dirList) ;                  sort($dirList) ;
700  ?>  ?>
701    
702  <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>
703    
704  <?php  <?php
705                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
706    
707                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
708                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
709                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
710                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
711                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
712  ?>  ?>
713    
714  <TR><TD><?php echo $gblIcon("fldr") ?></TD>  <TR><TD>
715  <TD COLSPAN=4 CLASS=LST><?php echo $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
716    <?= $gblIcon("fldr") ?></A></TD>
717    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
718    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
719    
720  <?php  <?php
721                  }  // iterate over dirs                  }  // iterate over dirs
722          }  // end if no dirs          }  // end if no dirs
723  ?>  ?>
724    
725  <TR><TD></TD><TD COLSPAN=4><HR><B><?php echo $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
726  </B></TD></TR>  </B></TD></TR>
727  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
728  <TD><?php echo $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
729    <TD CLASS=TOP>NOTE</TD>
730  <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>
731    
732  <?php  <?php
733          if (sizeof($fileList) > 0) {          if (sizeof($fileList) > 0) {
734            sort($fileList) ;            sort($fileList) ;
735            while (list($key,$file) = each($fileList)) {              while (list($key,$file) = each($fileList)) {  
736              $path = $fsDir."/".$file ;                  $path = $fsDir."/".$file ;
737              $mod  = filemtime($path) ;                  $mod  = filemtime($path) ;
738              $sz   = filesize($path) ;                  $sz   = filesize($path) ;
739    
740              if ($sz >= 10240) {                  if ($sz >= 10240) {
741                $sz = (int)(($sz+1023)/1024) . " k" ;                          $sz = (int)(($sz+1023)/1024) . " k" ;
742              }                  } else {
743              else {                          $sz .= " " ;
744                $sz .= " " ;                  } // end size
745              } // end size  
746                    $a = $b = "" ;
747              $a = $b = "" ;  
748                    $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
749              if ( ($mod + 30*86400) > time() ) {  
750                $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                  if ( ($mod + $gblModDays*86400) > time() ) {
751                $a .= " than 30 days\"> * </SPAN>" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
752              }                          $a .= " than $gblModDays days\"> * </SPAN>" ;
753                    }
754    
755                    $file_lock=CheckLock($path);
756    
757              $tstr = $webRoot . $relDir . "/" . $file ;                  $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
758              $tstr  = "<A HREF=\"" . $tstr . "\">" ;                  $file_url_html.="&D=".urlencode($relDir);
759                    $file_url_html.="\" TITLE=\"View file\">" ;
760    
761                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
762                          $tstr .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
763                  } else {                  } else {
764                          $tstr .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> deleted </span>";                          $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";
765                    }
766    
767                    $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
768    
769                    $ext = strtolower(strrchr($file,".")) ;
770    
771                    if ($file_lock) {
772                            if ($file_lock == $GLOBALS[gblUserName]) {
773                                    $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
774                                    $b.="&D=".urlencode($relDir);
775                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
776                                    $file_url_html=$b;
777                                    $b.=$gblIcon("checkin")."</A>" ;
778                                    $b.= $gblIcon("blank");
779                                    $file_url_html.="$file</a> $a";
780                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
781                            } else {
782                                    $b = $gblIcon("locked");
783                                    $b.= $gblIcon("blank");
784                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
785                                    $file_url_html = "$file $a";
786                            }
787                    } else {
788                            $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
789                            $b.="&D=".urlencode($relDir);
790                            $b.="\" TITLE=\"Checkout file for edit\">" ;
791                            $b.=$gblIcon("checkout")."</A>" ;
792    
793                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
794                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
795                                    $b.="&D=".urlencode($relDir);
796                                    $b.="\" TITLE=\"List contents\">" ;
797                                    $b.=$gblIcon("view")."</A>" ;
798                            } else {
799                                    $b.= $gblIcon("blank");
800                            }
801                  }                  }
802    
             $ext = strtolower(strrchr($file,".")) ;  
             if ( $ext=="" ||  
                  strstr(join(" ",$gblEditable),$ext) )  
             {    
               $b  = "<A HREF=\"" . $self . "?A=C&F=" ;  
               $b .= urlencode($file) . "&D=" . urlencode($relDir) ;  
               $b .= "\" TITLE=\"List contents\">" ;  
               $b .= $gblIcon("view") . "</A>" ;  
             }  
803    
804  ?>  ?>
805    
806  <TR><TD>  <TR><TD>
807  <A HREF="<?php echo $self ?>?A=E&F=<?php echo urlencode($file)  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
808  ?>&D=<?php echo urlencode($relDir) ?>" TITLE="View/Edit">  <?= $gblIcon($ext) ?></A></TD>
809  <?php echo $gblIcon($ext) ?></A></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
810  <TD CLASS=LST><?php echo $tstr ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
811  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
812  <TD CLASS=LST><?php echo date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
813  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
814    
815  <?php  <?php
816            }  // iterate over files            }  // iterate over files
817          }  // end if no files          } else {  // end if no files
818    ?>
819     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
820      No files in this directory
821     </TD></TR>
822    <?
823            }
824    
825          if ($emptyDir) {          if ($emptyDir) {
826  ?>  ?>
827    
828  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
829   <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>   <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
830    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
831    OK TO DELETE THIS EMPTY FOLDER?    OK TO DELETE THIS EMPTY FOLDER?
832    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
833    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
# Line 757  function Navigate($fsRoot,$relDir) { Line 838  function Navigate($fsRoot,$relDir) {
838          } // end if emptyDir          } // end if emptyDir
839  ?>  ?>
840    
841  <TR><TD></TD><TD COLSPAN=4><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
842    
843    <?
844    if (file_exists(".info.inc")) {
845            print "<TR><TD></TD><TD COLSPAN=5>";
846            include(".info.inc");
847            print "</TD></TR>
848            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
849    }
850    ?>
851    
852  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
853  <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
854   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
855   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
856   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
857   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
858   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
859   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
860   <NOBR>OR <A HREF="<?php echo $self   </NOBR>
861          ?>?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
862   </NOBR>   </NOBR>
863  </TD></TR>  </TD></TR>
864  </FORM>  </FORM>
# Line 780  function Navigate($fsRoot,$relDir) { Line 870  function Navigate($fsRoot,$relDir) {
870    
871  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
872    
873  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename="") {
874    
875          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
876          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 788  function UploadPage($fsRoot, $relDir) { Line 878  function UploadPage($fsRoot, $relDir) {
878    
879  <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>
880  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
881   ACTION="<?php echo $self ?>">   ACTION="<?= $self ?>">
882  DESTINATION DIRECTORY:<B><?php echo " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
883    <? if (isset($filename) && $filename!="") { ?>
884    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
885    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
886    <? } ?>
887  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
888  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
889  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
890  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
891  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
892  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
893  you must upgrade to an RFC1867-compliant browser.</P>  you must upgrade to an RFC1867-compliant browser.</P>
894  <P>Your browser:<BR><?php echo $GLOBALS["HTTP_USER_AGENT"] ?></P>  <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
895  </FORM>  </FORM>
896  </TD></TR>  </TD></TR>
897  <TR><TD></TD><TD>  <TR><TD></TD><TD>
898  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
899  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>"><BR>  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
900  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
901  </FORM>  </FORM>
902  </TD></TR></TABLE></P>  </TD></TR></TABLE></P>
# Line 821  function Error($title,$text="") { Line 915  function Error($title,$text="") {
915    
916  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
917    
 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>" ;  
         EndHTML() ;  
         exit ;  
   
 } // end function CreateHash  
   
 //////////////////////////////////////////////////////////////////  
   
918  function NoEntry() {  function NoEntry() {
919    
920          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 853  function NoEntry() { Line 924  function NoEntry() {
924          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
925          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
926          StartHTML($title,$text) ;          StartHTML($title,$text) ;
 ?>  
   
 <FORM ACTION="<?php echo $self ?>?HASH=create" METHOD="POST">  
 <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?php echo $user ?>">  
 <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?php echo $pw ?>">  
   
 <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>  
 Click below to <B>generate a password hash</B><BR>from  
 the username-password pair you just<BR>entered. Then include the hash in  
 the source<BR>of this file.<BR><BR>  
 <INPUT TYPE="SUBMIT" VALUE="CREATE HASH">  
 </BLOCKQUOTE></FORM>  
927    
 <?php  
928          EndHTML() ;          EndHTML() ;
929          exit ;          exit ;
930  }  }
931    
932  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
933    
934  function Logit($target,$msg) {  function LogIt($target,$msg) {
935    
936          $dir=dirname($target);          $dir=dirname($target);
937          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
# Line 889  function Logit($target,$msg) { Line 947  function Logit($target,$msg) {
947  }  }
948    
949    
950    //////////////////////////////////////////////////////////////////
951    
952    function WriteNote($target,$msg) {
953    
954            $target=stripSlashes($target);
955            $dir=dirname($target);
956            if (! file_exists($dir."/.note")) {
957                    mkdir($dir."/.note",0700);
958            }
959            $file=basename($target);
960    
961            $note=fopen("$dir/.note/$file","w");
962            fputs($note,"$msg\n");
963            fclose($note);
964    
965            Logit($target,"added note $msg");
966    
967    }
968    
969    function ReadNote($target) {
970    
971            $target=stripSlashes($target);
972            $dir=dirname($target);
973            $file=basename($target);
974            $msg="";
975            if (file_exists($dir."/.note/$file")) {
976                    $note=fopen("$dir/.note/$file","r");
977                    $msg=fgets($note,4096);
978                    fclose($note);
979            }
980            return StripSlashes($msg);
981    
982    }
983    
984    //////////////////////////////////////////////////////////////////
985    
986    function MoveTo($source,$folder) {
987    
988            $source=stripSlashes($source);
989            $file=basename($source);
990            if (! file_exists($folder)) {
991                    mkdir($folder,0700);
992            }
993            if (file_exists($source)) {
994                    rename($source,"$folder/$file");
995            }
996    }
997    
998    //////////////////////////////////////////////////////////////////
999    
1000    function Lock($target) {
1001    
1002            $target=stripSlashes($target);
1003            $dir=dirname($target);
1004            if (! file_exists($dir."/.lock")) {
1005                    mkdir($dir."/.lock",0700);
1006            }
1007            $file=basename($target);
1008    
1009            if (file_exists("$dir/.lock/$file")) {
1010                    Logit($target,"attempt to locked allready locked file!");
1011            } else {
1012                    $lock=fopen("$dir/.lock/$file","w");
1013                    fputs($lock,"$GLOBALS[gblUserName]\n");
1014                    fclose($lock);
1015    
1016                    Logit($target,"file locked");
1017            }
1018    
1019    }
1020    
1021    function CheckLock($target) {
1022    
1023            $target=stripSlashes($target);
1024            $dir=dirname($target);
1025            $file=basename($target);
1026            $msg=0;
1027            if (file_exists($dir."/.lock/$file")) {
1028                    $lock=fopen("$dir/.lock/$file","r");
1029                    $msg=fgets($lock,4096);
1030                    fclose($lock);
1031            }
1032            return chop($msg);
1033    
1034    }
1035    
1036    function Unlock($target) {
1037    
1038            $target=stripSlashes($target);
1039            $dir=dirname($target);
1040            $file=basename($target);
1041            if (file_exists($dir."/.lock/$file")) {
1042                    unlink("$dir/.lock/$file");
1043                    Logit($target,"file unlocked");
1044            } else {
1045                    Logit($target,"attempt to unlocked non-locked file!");
1046            }
1047    
1048    }
1049    
1050    //////////////////////////////////////////////////////////////////
1051    
1052    function urlpath($url) {
1053            $url=urlencode(StripSlashes("$url"));
1054            $url=str_replace("%2F","/",$url);
1055            $url=str_replace("+","%20",$url);
1056            return($url);
1057    }
1058    
1059    //////////////////////////////////////////////////////////////////
1060    
1061    function safe_rename($fromdir,$fromfile,$tofile) {
1062            function try_rename($from,$to) {
1063    #               print "$from -> $to\n";
1064                    if (file_exists($from) && is_writeable(dirname($to))) {
1065                            rename($from,$to);
1066                    }
1067            }
1068    
1069            function try_dir($todir) {
1070                    if (! file_exists($todir)) {
1071                            mkdir($todir,0700);
1072                    }
1073            }
1074    
1075            $to="$fromdir/$tofile";
1076            $todir=dirname($to);
1077            $tofile=basename($to);
1078    
1079    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1080    
1081            try_rename("$fromdir/$fromfile","$todir/$tofile");
1082            try_dir("$todir/.log");
1083            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1084            try_dir("$todir/.note");
1085            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1086            try_dir("$todir/.lock");
1087            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1088            try_dir("$todir/.bak");
1089            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1090                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1091            }
1092    }
1093    
1094    
1095    //////////////////////////////////////////////////////////////////
1096    
1097    // recursivly delete directory
1098    
1099    function rrmdir($dir) {
1100            $handle=opendir($dir);
1101            while ($file = readdir($handle)) {
1102                    if ($file != "." && $file != "..") {
1103                            if (is_dir("$dir/$file"))
1104                                    rrmdir("$dir/$file");
1105                            else
1106                                    if (! @unlink("$dir/$file")) return(0);
1107                    }
1108            }
1109            closedir($handle);
1110            return @rmdir($dir);
1111    }
1112    
1113    //////////////////////////////////////////////////////////////////
1114    
1115    function ChangeLog($target,$msg) {
1116    
1117            global $gblFsRoot;
1118            $log=fopen("$gblFsRoot/.changelog","a+");
1119            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1120                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1121            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1122            fclose($log);
1123    
1124    }
1125    
1126    function DisplayChangeLog($day) {
1127    
1128            global $gblFsRoot;
1129            if (!file_exists("$gblFsRoot/.changelog")) return;
1130            $log=fopen("$gblFsRoot/.changelog","r");
1131            $logarr = array();
1132            while($line = fgetcsv($log,255,"\t")) {
1133                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1134                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1135                    }
1136            }
1137            fclose($log);
1138            $cl1=" class=LST"; $cl2="";
1139            print "<table border=0 width=100%>\n";
1140            while ($e = array_shift($logarr)) {
1141                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1142                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1143                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1144                    $dir = dirname($e[1]);
1145                    $file = basename($e[1]);
1146                    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";
1147            }
1148            print "</table>";
1149            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1150    }
1151    
1152  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1153    
# Line 907  function Logit($target,$msg) { Line 1166  function Logit($target,$msg) {
1166          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1167          // creation if password not yet set.          // creation if password not yet set.
1168          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1169          if ($HASH != "") {  
1170                  CreateHash($USER, $PW) ;          $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
1171                  exit ;          if (! file_exists($htusers_file)) {
1172                    if (is_writeable(dirname($SCRIPT_FILENAME))) {
1173                            $htusers=fopen($htusers_file,"a+");
1174                            fputs($htusers,"# Change owner of $htusers_file to root !!\n");
1175                            fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");
1176                            fclose($htusers);
1177                            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!");
1178                            exit;
1179                    } else {
1180                            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!");
1181                            exit;
1182                    }
1183            }
1184            $htusers=fopen($htusers_file,"r");
1185            while($user = fgetcsv($htusers,255,":")) {
1186                    if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
1187                            $gblUserName=$user[1];
1188                            $gblPw=$user[2];
1189                            if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {
1190                                    require("$gblIncDir/$gblPw.php");
1191                                    if ($gblPw($user)) {
1192                                            $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1193                                    } else {
1194                                            $gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1195                                    }
1196                            }
1197                            $gblEmail=$user[3];
1198                            continue ;
1199                    }
1200          }          }
1201            fclose($htusers);
1202    
1203          // authentication if $gblAuth == true          // authentication failure
1204          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1205                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
1206                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1207                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1208                  NoEntry() ;                  NoEntry() ;
1209                  exit ;                  exit ;
# Line 927  function Logit($target,$msg) { Line 1215  function Logit($target,$msg) {
1215                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1216          }                }      
1217    
1218            $relDir=stripSlashes($relDir);
1219    
1220          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1221          // default : website root = ""          // default : website root = ""
1222    
# Line 938  function Logit($target,$msg) { Line 1228  function Logit($target,$msg) {
1228          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1229    
1230          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1231          // i.e. /siteman          // i.e. /docman
1232    
1233          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1234          // i.e. /home/httpd/html/siteman          // i.e. /home/httpd/html/docman
1235    
1236          $gblFsRoot = substr($fsScriptDir,0,          // start on server root
1237            strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1238            // or on script root
1239            $gblFsRoot = $fsScriptDir;
1240          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1241    
1242          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1243          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1244            
1245            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1246                    $webRoot  = "https://";
1247            } else {
1248                    $webRoot  = "http://";
1249            }
1250            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1251    
1252            $FN=stripSlashes($FN);
1253    
1254            if (file_exists("$fsScriptDir/.docman.conf")) {
1255                    include("$fsScriptDir/.docman.conf");
1256            }
1257    
1258          switch ($POSTACTION) {          switch ($POSTACTION) {
1259          case "UPLOAD" :          case "UPLOAD" :
1260                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 958  function Logit($target,$msg) { Line 1263  function Logit($target,$msg) {
1263                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1264                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1265                  $source = $FN ;                  $source = $FN ;
1266                  $target = $fsDir . "/" . $FN_name ;                  if (! file_exists($source)) {
1267                            Error("You must select file with browse to upload it!");
1268                    }
1269                    if (! isset($FILENAME)) {       // from update file
1270                            $target = "$fsDir/$FN_name" ;
1271                    } else {
1272                            $target = "$fsDir/$FILENAME";
1273                    }
1274    
1275                  // backup old files first                  // backup old files first
1276                  $dir=dirname($target);                  $dir=dirname($target);
# Line 970  function Logit($target,$msg) { Line 1282  function Logit($target,$msg) {
1282                  }                  }
1283                  $file=basename($target);                  $file=basename($target);
1284                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1285                          if (! file_exists($dir."/.bak/".$i)) {                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
                                 mkdir($dir."/.bak/".$i,0700);  
                         }  
                         if (file_exists($dir."/.bak/".$i."/".$file)) {  
                                 rename($dir."/.bak/".$i."/".$file,  
                                         $dir."/.bak/".($i+1)."/".$file);  
                         }  
                 }  
                 if (file_exists($target)) {  
                         rename($target,$dir."/.bak/1/".$file);  
1286                  }                  }
1287                    MoveTo($target,$dir."/.bak/1/");
1288    
1289                  copy($source,$target) ;                  copy($source,$target) ;
1290                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1291                  clearstatcache() ;                  clearstatcache() ;
1292                  Logit($target,"uploaded");                  Logit($target,"uploaded");
1293                    if (isset($FILENAME)) {
1294                            Unlock($target);
1295                    }
1296                    ChangeLog($target,"updated");
1297                  break ;                  break ;
1298    
1299          case "SAVE" :          case "SAVE" :
1300                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1301                    $path=stripSlashes($path);
1302                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1303                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1304                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 997  function Logit($target,$msg) { Line 1306  function Logit($target,$msg) {
1306                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1307                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1308                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1309                    $FILEDATA=stripSlashes($FILEDATA);
1310                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1311                  fclose($fh) ;                  fclose($fh) ;
1312                  clearstatcache() ;                  clearstatcache() ;
1313                  Logit($path,"saved changes");                  Logit($path,"saved changes");
1314                    ChangeLog($path,"saved changes");
1315                  break ;                  break ;
1316    
1317          case "CREATE" :          case "CREATE" :
# Line 1011  function Logit($target,$msg) { Line 1322  function Logit($target,$msg) {
1322                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1323                  switch ( $T ) {                  switch ( $T ) {
1324                  case "D" :  // create a directory                  case "D" :  // create a directory
1325                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1326                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1327                    clearstatcache() ;                          clearstatcache() ;
1328                    break ;                          break ;
1329                  case "F" :  // create a new file                  case "F" :  // create a new file
1330  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1331  // better keep it here altogether  // better keep it here altogether
1332  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1333                    if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1334                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1335                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1336                    header("Location: " . $tstr) ;                          if ($fh) {
1337                    exit ;                                  fputs($fh,"\n");
1338                                    fclose($fh) ;
1339                                    LogIt($path,"file created");
1340                            } else {
1341                                    Error("Creation of file $relPath failed -- $path");
1342                            }
1343                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1344                            header("Location: " . $tstr) ;
1345                            ChangeLog($target,"created");
1346                            exit ;
1347                  }                  }
1348                  break ;                  break ;
1349    
# Line 1049  function Logit($target,$msg) { Line 1369  function Logit($target,$msg) {
1369                                  exit ;                                  exit ;
1370                          } else {                          } else {
1371                                  Logit($path,"file deleted");                                  Logit($path,"file deleted");
1372                                  if (! file_exists("$dir/.del/.log")) {                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
1373                                          mkdir("$dir/.del/.log",0700);                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");
1374                                  }                                  MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
                                 rename("$dir/.log/$file","$dir/.del/.log/$file");  
1375                          }                          }
1376                  }                  }
1377                  else {  // delete directory                  else {  // delete directory
1378                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1379                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1380                    }                    }
1381                    else {                    else {
# Line 1072  function Logit($target,$msg) { Line 1391  function Logit($target,$msg) {
1391                  $file=substr($FN,4,strlen($FN)-4);                  $file=substr($FN,4,strlen($FN)-4);
1392    
1393                  Logit("$fsDir/.del/$file","undeleted");                  Logit("$fsDir/.del/$file","undeleted");
1394                  rename("$fsDir/.del/$file","$fsDir/$file");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1395                  rename("$fsDir/.del/.log/$file","$fsDir/.log/$file");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1396                    MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1397                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1398    
1399                  break ;                  break ;
1400    
# Line 1081  function Logit($target,$msg) { Line 1402  function Logit($target,$msg) {
1402                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1403    
1404                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1405                  rename("$fsDir/$FN","$fsDir/$NEWNAME");                  safe_rename($fsDir,$FN,$NEWNAME);
1406                  rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");                  break ;
1407    
1408            case "NOTE" :  
1409                    WriteNote("$fsDir/$FN","$NOTE");
1410                    break ;
1411    
1412            case "UNLOCK" :  
1413                    if ( $CONFIRM != "on" ) break ;
1414                    Unlock("$fsDir/$FN");
1415                  break ;                  break ;
1416    
1417          default :          default :
# Line 1101  function Logit($target,$msg) { Line 1429  function Logit($target,$msg) {
1429          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1430          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1431          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1432            // $A=Co : checkout file $D/$F
1433            // $A=Ci : checkin file $D/$F
1434            // $A=V : view file (do nothing except log)
1435          // default : display directory $D          // default : display directory $D
1436            
1437          switch ($A) {          switch ($A) {
1438          case "U" :          case "U" :
1439                  // upload to $relDir                  // upload to $relDir
1440                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1441                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1442                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1443                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1444                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1445                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1446                  EndHTML() ;                  EndHTML() ;
1447                  exit ;                  exit ;
1448          case "E" :          case "E" :
1449                    $F=stripSlashes($F);
1450                  // detail of $relDir/$F                  // detail of $relDir/$F
1451                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1452                  exit ;                  exit ;
1453          case "C" :          case "C" :
1454                    $F=stripSlashes($F);
1455                  // listing of $relDir/$F                  // listing of $relDir/$F
1456                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1457                  exit ;                  exit ;
1458            case "Co" :
1459                    // checkout
1460                    Lock("$gblFsRoot/$relDir/$F");
1461                    header("Content-Disposition: attachment; filename=$F" );
1462                    Header("Location: $webRoot".urlpath("$relDir/$F"));
1463                    exit;
1464            case "Ci" :
1465                    $F=stripSlashes($F);
1466                    // upload && update to $relDir
1467                    if (!is_writeable($gblFsRoot . $relDir))
1468                            Error("Write access denied",$relDir) ;
1469                    $text  = "Use this page to update a single " ;
1470                    $text .= "file to <B>$HTTP_HOST</B>." ;
1471                    StartHTML("(Update file Page)", $text) ;
1472                    UploadPage($gblFsRoot, $relDir, $F) ;
1473                    EndHTML() ;
1474                    exit ;
1475            case "V" :
1476                    // view
1477                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1478                    header("Content-Disposition: attachment; filename=$F" );
1479                    Header("Location: $webRoot".urlpath("$relDir/$F"));
1480                    exit;
1481            case "Ch" :
1482                    StartHTML("(File changes)","All changes chronologicaly...");
1483                    DisplayChangeLog(0);    // all
1484                    EndHTML() ;
1485                    exit;
1486            case "Ch1" :
1487                    StartHTML("(File changes)","Changes to files in last day...");
1488                    DisplayChangeLog(1);
1489                    EndHTML() ;
1490                    exit;
1491          }          }
1492    
1493          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.40

  ViewVC Help
Powered by ViewVC 1.1.26