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

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

  ViewVC Help
Powered by ViewVC 1.1.26