/[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.4 by dpavlin, Thu Aug 3 20:54:27 2000 UTC revision 1.56 by dpavlin, Thu Jan 24 09:09:12 2002 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          // username/password should not be system          // from where to include auth_*.php modules?
79          // usernames/passwords !!          $gblIncDir = "/home/httpd/docman";
80    
81  //      $gblPw    = "hash_of_your_username_and_password" ;          // do we want to force download? (default is 0 for backward
82            // compatibility, but it's defined as 1 in docman.conf for all
83            // future applications!
84            $gblForceDownload = 0;
85    
86  //      $gblAuth  = false ;             // use builtin authentication          // username/password should not be system
87          $gblAuth  = true ;             // use builtin authentication          // usernames/passwords !!
         $gblHash  = "md5" ;             // hash function to use  
88    
89          $gblPw    = "";          $gblPw    = "";
90    
91          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);  
         }  
   
92  //      $gblDateFmt="D, F d, Y";  //      $gblDateFmt="D, F d, Y";
 //      $gblTimeFmt="g:i:sA";  
   
93          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
94    
95            // time format
96    //      $gblTimeFmt="g:i:sA";
97          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
98    
99  // Number of backup files to keep          // Number of backup files to keep
100          $gblNumBackups=5;          $gblNumBackups=3;
101    
102            // show red star if newer than ... days
103            $gblModDays=1;
104    
105          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
106          // WingDings font installed on your system          // WingDings font installed on your system
107    
108          $gblIcon = "GifIcon" ;          // MockIcon or GifIcon          $gblIcon="GifIcon";             // MockIcon or GifIcon
109    
110          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
111          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
112    
113          $gblIconLocation = "/icons/" ;          $gblIconLocation="/icons/";
114    
115          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
116          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 146  TODO: Line 125  TODO:
125          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",
126                                ".bmp",".xbm") ;                                ".bmp",".xbm") ;
127    
128            // which files to hide (separated by ,)
129            $gblHide = "";
130    
131            // Where are users? (by default in .htusers file)
132            $gblUsers = "htusers_file";
133    
134  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
135    
136            $gblVersion = "1.9-dev";
137    
138  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
139    
140          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
141          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
142          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
143  ?>  ?>
# Line 158  function StartHTML($title,$text="") { Line 145  function StartHTML($title,$text="") {
145  <HTML>  <HTML>
146  <HEAD>  <HEAD>
147   <TITLE><?= $host . " " . $title ?></TITLE>   <TITLE><?= $host . " " . $title ?></TITLE>
148   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">   <META NAME="description" CONTENT="Document Manager">
149   <META NAME="keywords" CONTENT="site manager, web site maintenance">   <META NAME="keywords" CONTENT="site manager, web site maintenance">
150   <META NAME="robots" CONTENT="noindex">   <META NAME="robots" CONTENT="noindex">
151   <META HTTP-EQUIV="expires" CONTENT="0">   <META HTTP-EQUIV="expires" CONTENT="0">
# Line 177  function StartHTML($title,$text="") { Line 164  function StartHTML($title,$text="") {
164  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
165    
166  function EndHTML() {  function EndHTML() {
167    
168    global $gblDateFmt, $gblTimeFmt, $gblUserName, $PHP_SELF, $gblPw, $gblVersion;
169    
170  ?>  ?>
171    
172  <HR>  <HR>
173  <P CLASS=FTR>  <P CLASS=FTR>
174  <B><?= date($GLOBALS[gblDateFmt]) ?> -  <B><?= date($gblDateFmt) ?> -
175  <?= date($GLOBALS[gblTimeFmt]) ?> -  <?= date($gblTimeFmt) ?> -
176  <?= $GLOBALS[gblUserName] ?>  <?= $gblUserName ?>
177  <small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>  <?php
178            global $PHP_AUTH_USER,$PHP_AUTH_PW;
179            $url = $PHP_SELF."?relogin=";
180            if (isset($gblPw) && $gblPw != "") {
181                    $url .= $gblPw;
182            } else {
183                    $url .= md5($PHP_AUTH_USER.$PHP_AUTH_PW);
184            }
185            if (isset($PHP_AUTH_USER) && $PHP_AUTH_USER != "" && ($PHP_AUTH_PW == "" || !isset($PHP_AUTH_PW))) {
186                    $url_title="login";
187                    $url .= "&force_login=1";
188            } else {
189                    $url_title="relogin";
190            }
191    ?>
192    <small> [<a href="<?= $url ?>"><?= $url_title ?></a>]</small>
193  </B>  </B>
194  <BR>ANYPORTAL(php) Site Manager  <BR><small>
195  <br><small>  Document Manager <?= $gblVersion ?>, based on ANYPORTAL(php) Site Manager
196    <br>
197  &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,  &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
198  &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,  &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
199  &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>  &copy; 2000-2002 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
200  </small>  </small>
201  </P>  </P>
202  <BR>  <BR>
203  <? include(".debug.inc") ?>  <? //include(".debug.inc") ?>
204  <BR><BR></BODY></HTML>  <BR><BR></BODY></HTML>
205    
206  <?php  <?php
# Line 229  A:HOVER { color:red; } Line 235  A:HOVER { color:red; }
235    
236  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
237                    
238          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
239          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
240    
241          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 240  function DetailPage($fsRoot,$relDir,$fn) Line 246  function DetailPage($fsRoot,$relDir,$fn)
246          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
247          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
248          $writable = is_writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
249            $file_lock = CheckLock($fsPath);
250    
251          if (!$editable && !$exists)          if (!$editable && !$exists)
252                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
# Line 247  function DetailPage($fsRoot,$relDir,$fn) Line 254  function DetailPage($fsRoot,$relDir,$fn)
254                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
255    
256          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
257          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
258                    $text .="delete a directory on this " ;
259            } else {
260                    $text .= "delete a single document on this " ;
261            };
262          $text .= "web site." ;            $text .= "web site." ;  
263          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
264          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 257  function DetailPage($fsRoot,$relDir,$fn) Line 268  function DetailPage($fsRoot,$relDir,$fn)
268                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
269                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
270                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
271                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
272                    $fgid=filegroup($fsPath);
273                    $userinfo = posix_getpwuid($fuid);
274                    $grpinfo = posix_getgrgid($fgid);
275                    echo "<PRE>";
276                    if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
277                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
278                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
279                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
280                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
281                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
282                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
283                  echo "</PRE>" ;                  echo "</PRE>" ;
284    
285          }          }
286    
287          if ( $editable && ($writable || !$exists) ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
288                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
289                  rewind($fh) ;                  rewind($fh) ;
290                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 294  echo($fstr) ; ?></TEXTAREA> Line 310  echo($fstr) ; ?></TEXTAREA>
310    
311  <?php  <?php
312          }          }
313          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
314            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
315            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
316            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
317            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
318            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
319                    echo $tstr ;
320          }          }
321    
322  ?>  ?>
323    
324  <FORM ACTION="<?= $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
# Line 309  echo($fstr) ; ?></TEXTAREA> Line 327  echo($fstr) ; ?></TEXTAREA>
327  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
328    
329  <?php  <?php
330    
331            if ($file_lock) {
332    ?>
333    <hr>
334    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
335    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
336    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
337    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
338    <?
339            } // file_lock
340    
341          if (substr($fn,0,4) == ".del") {          if (substr($fn,0,4) == ".del") {
342                  $action="UNDELETE";                  $action="UNDELETE";
343                  $desc="undelete previously deleted file";                  $desc="undelete previously deleted file";
# Line 336  echo($fstr) ; ?></TEXTAREA> Line 365  echo($fstr) ; ?></TEXTAREA>
365  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
366  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
367    
368    <?php
369            }       // exists && writable
370    ?>
371  <HR>  <HR>
372  <a name="note">  <a name="note">
373  <B>NOTE FOR "<?= $fn ; ?>":  <B>NOTE FOR "<?= $fn ; ?>":
# Line 343  echo($fstr) ; ?></TEXTAREA> Line 375  echo($fstr) ; ?></TEXTAREA>
375  </B></SPAN>  </B></SPAN>
376  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
377    
378    </FORM>
379    
380  <?php  <?php
         }  
         echo "</FORM>" ;  
381    
382          $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
383            $logname=dirname("$fsDir/$fn")."/.log/$name";
384            $bakdir=dirname("$fsDir/$fn")."/.bak";
385          if (file_exists($logname)) {          if (file_exists($logname)) {
                 print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";  
386                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
387                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
388                  while($line = fgetcsv($log,255,"\t")) {                  $logarr = array();
389                    while($line = fgetcsv($log,512,"\t")) {
390                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
391                          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]));
392                  }                  }
393                  fclose($log);                  fclose($log);
394                    if (is_dir("$fsDir/$fn")) {
395                            $whatis="DIRECTORY";
396                    } else {
397                            $whatis="FILE";
398                    }
399                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
400                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
401                    while ($e = array_shift($logarr)) {
402                            if (strstr($e[4],"upload")) {
403                                    if (file_exists("$bakdir/$bakcount/$name")) {
404                                            $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
405                                    }
406                                    $bakcount++;
407                            }
408                            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";
409                    }
410                  print "</table>";                  print "</table>";
411          }          }
412    
# Line 590  function GifIcon($txt) { Line 640  function GifIcon($txt) {
640                  $d = "blank.gif" ;                  $d = "blank.gif" ;
641                  break ;                  break ;
642          case "checkout":          case "checkout":
643                  $d = "down.gif";                  $d = "box2.gif";
644                  break;                  break;
645          case "checkin":          case "checkin":
646                  $d = "up.gif";                  $d = "hand.up.gif";
647                    break;
648            case "locked":
649                    $d = "screw2.gif";
650                  break;                  break;
651          case "note":          case "note":
652                  $d = "quill.gif";                  $d = "quill.gif";
# Line 609  function GifIcon($txt) { Line 662  function GifIcon($txt) {
662    
663  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
664    
665          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ;
666    
667          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
668          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
669                  $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
670    
671          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
672    
673            $hide_items=",$gblHide,";
674    
675          // read directory contents          // read directory contents
676          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
677                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
678          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
679                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
680                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
681                          $dirList[] = $item ;                          $dirList[] = $item ;
682                  } else if ( is_file($fsDir . $item) ) {                  } else if ( is_file($fsDir . $item) ) {
# Line 644  function Navigate($fsRoot,$relDir) { Line 695  function Navigate($fsRoot,$relDir) {
695          // scan deleted files          // scan deleted files
696          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
697                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
698                          if ( substr($item,0,1) == "." ) continue ;                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
699                          $fileList[] = ".del/$item" ;                                      $fileList[] = ".del/$item" ;            
700                  }                  }
701                  closedir($dir) ;                  closedir($dir) ;
# Line 655  function Navigate($fsRoot,$relDir) { Line 706  function Navigate($fsRoot,$relDir) {
706          // start navigation page          // start navigation page
707          $text  = "Use this page to add, delete";          $text  = "Use this page to add, delete";
708          if (! isset($show_deleted)) {          if (! isset($show_deleted)) {
709                  $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>";
710          }          }
711          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
712            $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>.";
713          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
714    
715          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
716                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
717    
718          // updir bar              // updir bar    
719          if ($fsDir != $fsRoot) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
720                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
721                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
722  ?>  ?>
# Line 676  function Navigate($fsRoot,$relDir) { Line 728  function Navigate($fsRoot,$relDir) {
728  <?php  <?php
729          }          }
730    
731    function plural($name,$count) {
732            $out="$count $name";
733            if ($count > 1) {
734                    $out.="s";
735            }
736            return $out;
737    }
738    
739          // output subdirs          // output subdirs
740          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
741                  sort($dirList) ;                  sort($dirList) ;
742  ?>  ?>
743    
744  <TR><TD></TD><TD COLSPAN=5 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>
745    
746  <?php  <?php
747                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
748    
749                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
750                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
751                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
752                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
753                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
754  ?>  ?>
755    
756  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
757  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
758    <?= $gblIcon("fldr") ?></A></TD>
759    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
760    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
761    
762  <?php  <?php
763                  }  // iterate over dirs                  }  // iterate over dirs
# Line 701  function Navigate($fsRoot,$relDir) { Line 766  function Navigate($fsRoot,$relDir) {
766    
767  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
768  </B></TD></TR>  </B></TD></TR>
769  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
770  <TD><?= $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
771  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
772  <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>
773    
# Line 724  function Navigate($fsRoot,$relDir) { Line 789  function Navigate($fsRoot,$relDir) {
789    
790                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
791    
792                  if ( ($mod + 30*86400) > time() ) {                  if ( ($mod + $gblModDays*86400) > time() ) {
793                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
794                          $a .= " than 30 days\"> * </SPAN>" ;                          $a .= " than $gblModDays days\"> * </SPAN>" ;
795                  }                  }
796    
797                  $tstr = $webRoot . $relDir . "/" . $file ;                  $file_lock=CheckLock($path);
798                  $tstr  = "<A HREF=\"" . $tstr . "\">" ;  
799                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
800                    $file_url_html.="&D=".urlencode($relDir);
801                    $file_url_html.="\" TITLE=\"View file\">" ;
802    
803                  if (substr($file,0,5) != ".del/") {                  if (substr($file,0,5) != ".del/") {
804                          $tstr .= $file . "</A>" . $a ;                          $file_url_html .= $file . "</A>" . $a ;
805                  } else {                  } else {
806                          $tstr .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";                          $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";
807                  }                  }
808    
809  //              $b = $gblIcon("checkout");                  $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
 //              $b .= $gblIcon("checkin");  
810    
811                  $ext = strtolower(strrchr($file,".")) ;                  $ext = strtolower(strrchr($file,".")) ;
812                  if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {    
813                          $b .= "<A HREF=\"" . $self . "?A=C&F=" ;                  if ($file_lock) {
814                          $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                          if ($file_lock == $GLOBALS[gblUserName]) {
815                          $b .= "\" TITLE=\"List contents\">" ;                                  $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
816                          $b .= $gblIcon("view") . "</A>" ;                                  $b.="&D=".urlencode($relDir);
817                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
818                                    $file_url_html=$b;
819                                    $b.=$gblIcon("checkin")."</A>" ;
820                                    $b.= $gblIcon("blank");
821                                    $file_url_html.="$file</a> $a";
822                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
823                            } else {
824                                    $b = $gblIcon("locked");
825                                    $b.= $gblIcon("blank");
826                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
827                                    $file_url_html = "$file $a";
828                            }
829                  } else {                  } else {
830                          $b .= $gblIcon("blank");                          $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
831                            $b.="&D=".urlencode($relDir);
832                            $b.="\" TITLE=\"Checkout file for edit\">" ;
833                            $b.=$gblIcon("checkout")."</A>" ;
834    
835                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
836                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
837                                    $b.="&D=".urlencode($relDir);
838                                    $b.="\" TITLE=\"List contents\">" ;
839                                    $b.=$gblIcon("view")."</A>" ;
840                            } else {
841                                    $b.= $gblIcon("blank");
842                            }
843                  }                  }
844    
845    
# Line 757  function Navigate($fsRoot,$relDir) { Line 848  function Navigate($fsRoot,$relDir) {
848  <TR><TD>  <TR><TD>
849  <A HREF="<?= $info_url ?>" TITLE="View/Edit">  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
850  <?= $gblIcon($ext) ?></A></TD>  <?= $gblIcon($ext) ?></A></TD>
851  <TD CLASS=LST><?= $tstr ?></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
852  <TD CLASS=LST ALIGN=center><?= $b ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
853  <TD CLASS=LST ALIGN=left><a href="<?= $info_url ?>#note"><?= $gblIcon("note") ?></a><?= ReadNote($path) ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
854  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
855  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
856    
857  <?php  <?php
858            }  // iterate over files            }  // iterate over files
859          }  // end if no files          } else {  // end if no files
860    ?>
861     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
862      No files in this directory
863     </TD></TR>
864    <?
865            }
866    
867          if ($emptyDir) {          if ($emptyDir && $relDir != "") {
868  ?>  ?>
869    
870  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 785  function Navigate($fsRoot,$relDir) { Line 882  function Navigate($fsRoot,$relDir) {
882    
883  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
884    
885    <?
886    if (file_exists(".info.inc")) {
887            print "<TR><TD></TD><TD COLSPAN=5>";
888            include(".info.inc");
889            print "</TD></TR>
890            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
891    }
892    ?>
893    
894  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
895  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
896   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
# Line 792  function Navigate($fsRoot,$relDir) { Line 898  function Navigate($fsRoot,$relDir) {
898   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
899   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
900   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
901   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
902   <NOBR>OR <A HREF="<?= $self   </NOBR>
903          ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
904   </NOBR>   </NOBR>
905  </TD></TR>  </TD></TR>
906  </FORM>  </FORM>
# Line 806  function Navigate($fsRoot,$relDir) { Line 912  function Navigate($fsRoot,$relDir) {
912    
913  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
914    
915  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename="") {
916    
917          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
918          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 816  function UploadPage($fsRoot, $relDir) { Line 922  function UploadPage($fsRoot, $relDir) {
922  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
923   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
924  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
925    <? if (isset($filename) && $filename!="") { ?>
926    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
927    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
928    <? } ?>
929  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
930  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
931  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
# Line 847  function Error($title,$text="") { Line 957  function Error($title,$text="") {
957    
958  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
959    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
960  function NoEntry() {  function NoEntry() {
961    
962          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 878  function NoEntry() { Line 965  function NoEntry() {
965    
966          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
967          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
         StartHTML($title,$text) ;  
 ?>  
968    
969  <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">          global $PHP_AUTH_USER,$PHP_AUTH_PW,$gblPw,$relogin;
970  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">          StartHTML($title,$text) ;
 <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $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>  
971    
 <?php  
972          EndHTML() ;          EndHTML() ;
973          exit ;          exit ;
974  }  }
975    
976  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
977    
978  function Logit($target,$msg) {  function LogIt($target,$msg) {
979    
980          $dir=dirname($target);          $dir=dirname($target);
981          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
# Line 919  function Logit($target,$msg) { Line 995  function Logit($target,$msg) {
995    
996  function WriteNote($target,$msg) {  function WriteNote($target,$msg) {
997    
998            $target=stripSlashes($target);
999          $dir=dirname($target);          $dir=dirname($target);
1000          if (! file_exists($dir."/.note")) {          if (! file_exists($dir."/.note")) {
1001                  mkdir($dir."/.note",0700);                  mkdir($dir."/.note",0700);
# Line 935  function WriteNote($target,$msg) { Line 1012  function WriteNote($target,$msg) {
1012    
1013  function ReadNote($target) {  function ReadNote($target) {
1014    
1015            $target=stripSlashes($target);
1016          $dir=dirname($target);          $dir=dirname($target);
1017          $file=basename($target);          $file=basename($target);
1018          $msg="";          $msg="";
# Line 943  function ReadNote($target) { Line 1021  function ReadNote($target) {
1021                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
1022                  fclose($note);                  fclose($note);
1023          }          }
1024          return $msg;          return HtmlSpecialChars(StripSlashes($msg));
1025    
1026  }  }
1027    
# Line 951  function ReadNote($target) { Line 1029  function ReadNote($target) {
1029    
1030  function MoveTo($source,$folder) {  function MoveTo($source,$folder) {
1031    
1032            $source=stripSlashes($source);
1033          $file=basename($source);          $file=basename($source);
1034          if (! file_exists($folder)) {          if (! file_exists($folder)) {
1035                  mkdir($folder,0700);                  mkdir($folder,0700);
# Line 962  function MoveTo($source,$folder) { Line 1041  function MoveTo($source,$folder) {
1041    
1042  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1043    
1044    function Lock($target) {
1045    
1046            $target=stripSlashes($target);
1047            $dir=dirname($target);
1048            if (! file_exists($dir."/.lock")) {
1049                    mkdir($dir."/.lock",0700);
1050            }
1051            $file=basename($target);
1052    
1053            if (file_exists("$dir/.lock/$file")) {
1054                    Logit($target,"attempt to locked allready locked file!");
1055            } else {
1056                    $lock=fopen("$dir/.lock/$file","w");
1057                    fputs($lock,"$GLOBALS[gblUserName]\n");
1058                    fclose($lock);
1059    
1060                    Logit($target,"file locked");
1061            }
1062    
1063    }
1064    
1065    function CheckLock($target) {
1066    
1067            $target=stripSlashes($target);
1068            $dir=dirname($target);
1069            $file=basename($target);
1070            $msg=0;
1071            if (file_exists($dir."/.lock/$file")) {
1072                    $lock=fopen("$dir/.lock/$file","r");
1073                    $msg=fgets($lock,4096);
1074                    fclose($lock);
1075            }
1076            return chop($msg);
1077    
1078    }
1079    
1080    function Unlock($target) {
1081    
1082            $target=stripSlashes($target);
1083            $dir=dirname($target);
1084            $file=basename($target);
1085            if (file_exists($dir."/.lock/$file")) {
1086                    unlink("$dir/.lock/$file");
1087                    Logit($target,"file unlocked");
1088            } else {
1089                    Logit($target,"attempt to unlocked non-locked file!");
1090            }
1091    
1092    }
1093    
1094    //////////////////////////////////////////////////////////////////
1095    
1096    function urlpath($url) {
1097            $url=urlencode(StripSlashes("$url"));
1098            $url=str_replace("%2F","/",$url);
1099            $url=str_replace("+","%20",$url);
1100            return($url);
1101    }
1102    
1103    //////////////////////////////////////////////////////////////////
1104    
1105    function safe_rename($fromdir,$fromfile,$tofile) {
1106            function try_rename($from,$to) {
1107    #               print "$from -> $to\n";
1108                    if (file_exists($from) && is_writeable(dirname($to))) {
1109                            rename($from,$to);
1110                    }
1111            }
1112    
1113            function try_dir($todir) {
1114                    if (! file_exists($todir)) {
1115                            mkdir($todir,0700);
1116                    }
1117            }
1118    
1119            $to="$fromdir/$tofile";
1120            $todir=dirname($to);
1121            $tofile=basename($to);
1122    
1123    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1124    
1125            try_rename("$fromdir/$fromfile","$todir/$tofile");
1126            try_dir("$todir/.log");
1127            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1128            try_dir("$todir/.note");
1129            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1130            try_dir("$todir/.lock");
1131            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1132            try_dir("$todir/.bak");
1133            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1134                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1135            }
1136    }
1137    
1138    
1139    //////////////////////////////////////////////////////////////////
1140    
1141    // recursivly delete directory
1142    
1143    function rrmdir($dir) {
1144            $handle=opendir($dir);
1145            while ($file = readdir($handle)) {
1146                    if ($file != "." && $file != "..") {
1147                            if (is_dir("$dir/$file"))
1148                                    rrmdir("$dir/$file");
1149                            else
1150                                    if (! @unlink("$dir/$file")) return(0);
1151                    }
1152            }
1153            closedir($handle);
1154            return @rmdir($dir);
1155    }
1156    
1157    //////////////////////////////////////////////////////////////////
1158    
1159    function ChangeLog($target,$msg) {
1160    
1161            global $gblFsRoot;
1162            $log=fopen("$gblFsRoot/.changelog","a+");
1163            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1164                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1165            $msg=str_replace("\t"," ",$msg);
1166            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1167            fclose($log);
1168    
1169    }
1170    
1171    function DisplayChangeLog($day) {
1172    
1173            global $gblFsRoot;
1174            if (!file_exists("$gblFsRoot/.changelog")) return;
1175            $log=fopen("$gblFsRoot/.changelog","r");
1176            $logarr = array();
1177            while($line = fgetcsv($log,512,"\t")) {
1178                    while (sizeof($line) > 4) {
1179                            $tmp = array_pop($line);
1180                            $line.=" $tmp";
1181                    }
1182                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1183                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1184                    }
1185            }
1186            fclose($log);
1187            $cl1=" class=LST"; $cl2="";
1188            print "<table border=0 width=100%>\n";
1189            while ($e = array_shift($logarr)) {
1190                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1191                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1192                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1193                    $dir = dirname($e[1]);
1194                    $file = basename($e[1]);
1195                    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";
1196            }
1197            print "</table>";
1198            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1199    }
1200    
1201    //////////////////////////////////////////////////////////////////
1202    
1203    function Download($path) {
1204            global $HTTP_USER_AGENT;
1205            $file=basename($path);
1206            $size = filesize($path);
1207            //header("Content-Type: application/octet-stream");
1208            header("Content-Type: application/force-download");
1209            header("Content-Length: $size");
1210            // IE5.5 just downloads index.php if we don't do this
1211            if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {
1212                    header("Content-Disposition: filename=$file");
1213            } else {
1214                    header("Content-Disposition: attachment; filename=$file");
1215            }
1216            header("Content-Transfer-Encoding: binary");
1217            $fh = fopen($path, "r");
1218            fpassthru($fh);
1219    }
1220    
1221    
1222    //////////////////////////////////////////////////////////////////
1223    
1224    function chopsl($path) {
1225            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1226            $path=str_replace("//","/",$path);
1227            return $path;
1228    }
1229    
1230    //////////////////////////////////////////////////////////////////
1231  // MAIN PROGRAM  // MAIN PROGRAM
1232  // ============  // ============
1233  // query parameters: capital letters  // query parameters: capital letters
# Line 976  function MoveTo($source,$folder) { Line 1242  function MoveTo($source,$folder) {
1242    
1243          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1244          // creation if password not yet set.          // creation if password not yet set.
1245          if ($STYLE == "get") { CSS() ; exit ; }          if (isset($STYLE) && $STYLE == "get") { CSS() ; exit ; }
1246          if ($HASH != "") {  
1247                  CreateHash($USER, $PW) ;          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1248                  exit ;          // i.e. /home/httpd/html/docman
1249    
1250            // read user-defined configuration
1251            if (file_exists("$fsScriptDir/.docman.conf")) {
1252                    include("$fsScriptDir/.docman.conf");
1253            }
1254    
1255            // where do we get users from?
1256            if (file_exists("$gblIncDir/$gblUsers.php")) {
1257                    include("$gblIncDir/$gblUsers.php");
1258            } else {
1259                    Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>");
1260            }
1261    
1262            // if no password, or empty password logout
1263            if (
1264                    isset($PHP_AUTH_USER) && (
1265                            !isset($relogin) || (
1266                                    isset($relogin) && $relogin != md5($PHP_AUTH_USER.$PHP_AUTH_PW)
1267                            )
1268                    ) && (
1269                            $PHP_AUTH_PW == "" || !isset($PHP_AUTH_PW)
1270                    ) && !isset($force_login)
1271               ) {
1272                    StartHTML("Logout completed","Your login credentials has been erased") ;
1273                    EndHTML() ;
1274                    exit ;
1275          }          }
1276    
1277          // authentication if $gblAuth == true          // authentication failure
1278          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1279                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin) {
1280                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  $realm="$HTTP_HOST";
1281                    header("WWW-authenticate: basic realm=\"$realm\"") ;
1282                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1283                  NoEntry() ;                  NoEntry() ;
1284                  exit ;                  exit ;
# Line 997  function MoveTo($source,$folder) { Line 1290  function MoveTo($source,$folder) {
1290                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1291          }                }      
1292    
1293            $relDir=stripSlashes($relDir);
1294    
1295          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1296          // default : website root = ""          // default : website root = ""
1297    
# Line 1008  function MoveTo($source,$folder) { Line 1303  function MoveTo($source,$folder) {
1303          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1304    
1305          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1306          // i.e. /siteman          // i.e. /docman
1307    
1308          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              // start on server root
1309          // i.e. /home/httpd/html/siteman  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1310            // or on script root
1311          $gblFsRoot = substr($fsScriptDir,0,          $gblFsRoot = $fsScriptDir;
           strlen($fsScriptDir)-strlen($relScriptDir)) ;  
1312          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1313    
1314          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1315          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1316            
1317            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1318                    $webRoot  = "https://";
1319            } else {
1320                    $webRoot  = "http://";
1321            }
1322            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1323    
1324            $FN=stripSlashes($FN);
1325    
1326    
1327          switch ($POSTACTION) {          switch ($POSTACTION) {
1328          case "UPLOAD" :          case "UPLOAD" :
1329                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1028  function MoveTo($source,$folder) { Line 1332  function MoveTo($source,$folder) {
1332                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1333                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1334                  $source = $FN ;                  $source = $FN ;
1335                  $target = $fsDir . "/" . $FN_name ;                  if (! file_exists($source)) {
1336                            Error("You must select file with browse to upload it!");
1337                    }
1338                    if (! isset($FILENAME)) {       // from update file
1339                            $target = "$fsDir/$FN_name" ;
1340                    } else {
1341                            $target = "$fsDir/$FILENAME";
1342                    }
1343    
1344                  // backup old files first                  // backup old files first
1345                  $dir=dirname($target);                  $dir=dirname($target);
# Line 1042  function MoveTo($source,$folder) { Line 1353  function MoveTo($source,$folder) {
1353                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {                  for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1354                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");                          MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1355                  }                  }
1356                  MoveTo($target,$dir."/.bak/1/".$file);                  MoveTo($target,$dir."/.bak/1/");
1357    
1358                  copy($source,$target) ;                  copy($source,$target) ;
1359                  chmod($target,$gblFilePerms) ;                  chmod($target,$gblFilePerms) ;
1360                  clearstatcache() ;                  clearstatcache() ;
1361                  Logit($target,"uploaded");                  Logit($target,"uploaded");
1362                    if (isset($FILENAME)) {
1363                            Unlock($target);
1364                    }
1365                    ChangeLog($target,"updated");
1366                  break ;                  break ;
1367    
1368          case "SAVE" :          case "SAVE" :
1369                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1370                    $path=stripSlashes($path);
1371                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1372                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1373                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 1059  function MoveTo($source,$folder) { Line 1375  function MoveTo($source,$folder) {
1375                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1376                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1377                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1378                    $FILEDATA=stripSlashes($FILEDATA);
1379                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1380                  fclose($fh) ;                  fclose($fh) ;
1381                  clearstatcache() ;                  clearstatcache() ;
1382                  Logit($path,"saved changes");                  Logit($path,"saved changes");
1383                    ChangeLog($path,"saved changes");
1384                  break ;                  break ;
1385    
1386          case "CREATE" :          case "CREATE" :
# Line 1073  function MoveTo($source,$folder) { Line 1391  function MoveTo($source,$folder) {
1391                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1392                  switch ( $T ) {                  switch ( $T ) {
1393                  case "D" :  // create a directory                  case "D" :  // create a directory
1394                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1395                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1396                    clearstatcache() ;                          clearstatcache() ;
1397                    break ;                          break ;
1398                  case "F" :  // create a new file                  case "F" :  // create a new file
1399  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1400  // better keep it here altogether  // better keep it here altogether
1401  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1402                    if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1403                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1404                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1405                    header("Location: " . $tstr) ;                          if ($fh) {
1406                    exit ;                                  fputs($fh,"\n");
1407                                    fclose($fh) ;
1408                                    LogIt($path,"file created");
1409                            } else {
1410                                    Error("Creation of file $relPath failed -- $path");
1411                            }
1412                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1413                            header("Location: " . $tstr) ;
1414                            ChangeLog($target,"created");
1415                            exit ;
1416                  }                  }
1417                  break ;                  break ;
1418    
# Line 1111  function MoveTo($source,$folder) { Line 1438  function MoveTo($source,$folder) {
1438                                  exit ;                                  exit ;
1439                          } else {                          } else {
1440                                  Logit($path,"file deleted");                                  Logit($path,"file deleted");
                                 if (! file_exists("$dir/.del/.log")) {  
                                         mkdir("$dir/.del/.log",0700);  
                                 }  
1441                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");                                  MoveTo("$dir/.log/$file","$dir/.del/.log/");
1442                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");                                  MoveTo("$dir/.note/$file","$dir/.del/.note/");
1443                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1444                          }                          }
1445                  }                  }
1446                  else {  // delete directory                  else {  // delete directory
1447                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1448                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1449                    }                    }
1450                    else {                    else {
# Line 1138  function MoveTo($source,$folder) { Line 1463  function MoveTo($source,$folder) {
1463                  MoveTo("$fsDir/.del/$file","$fsDir/");                  MoveTo("$fsDir/.del/$file","$fsDir/");
1464                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");                  MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1465                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");                  MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1466                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1467    
1468                  break ;                  break ;
1469    
# Line 1145  function MoveTo($source,$folder) { Line 1471  function MoveTo($source,$folder) {
1471                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1472    
1473                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1474                  rename("$fsDir/$FN","$fsDir/$NEWNAME");                  safe_rename($fsDir,$FN,$NEWNAME);
                 rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");  
   
1475                  break ;                  break ;
1476    
1477          case "NOTE" :            case "NOTE" :  
1478                  WriteNote("$fsDir/$FN","$NOTE");                  WriteNote("$fsDir/$FN","$NOTE");
1479                  break ;                  break ;
1480    
1481            case "UNLOCK" :  
1482                    if ( $CONFIRM != "on" ) break ;
1483                    Unlock("$fsDir/$FN");
1484                    break ;
1485    
1486          default :          default :
1487                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1488          }          }
# Line 1169  function MoveTo($source,$folder) { Line 1498  function MoveTo($source,$folder) {
1498          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1499          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1500          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1501            // $A=Co : checkout file $D/$F
1502            // $A=Ci : checkin file $D/$F
1503            // $A=V : view file (do nothing except log)
1504            // $A=I : include file .$F.php from $gblFsRoot
1505          // default : display directory $D          // default : display directory $D
1506            
1507          switch ($A) {          switch ($A) {
1508          case "U" :          case "U" :
1509                  // upload to $relDir                  // upload to $relDir
1510                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1511                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1512                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1513                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1514                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1515                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1516                  EndHTML() ;                  EndHTML() ;
1517                  exit ;                  exit ;
1518          case "E" :          case "E" :
1519                    $F=stripSlashes($F);
1520                  // detail of $relDir/$F                  // detail of $relDir/$F
1521                  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) ;
1522                  exit ;                  exit ;
1523          case "C" :          case "C" :
1524                    $F=stripSlashes($F);
1525                  // listing of $relDir/$F                  // listing of $relDir/$F
1526                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1527                  exit ;                  exit ;
1528            case "Co" :
1529                    // checkout
1530                    Lock("$gblFsRoot/$relDir/$F");
1531                    Download("$gblFsRoot/$relDir/$F");
1532                    exit;
1533            case "Ci" :
1534                    $F=stripSlashes($F);
1535                    // upload && update to $relDir
1536                    if (!is_writeable($gblFsRoot . $relDir))
1537                            Error("Write access denied",$relDir) ;
1538                    $text  = "Use this page to update a single " ;
1539                    $text .= "file to <B>$HTTP_HOST</B>." ;
1540                    StartHTML("(Update file Page)", $text) ;
1541                    UploadPage($gblFsRoot, $relDir, $F) ;
1542                    EndHTML() ;
1543                    exit ;
1544            case "V" :
1545                    // view
1546                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1547                    if ($gblForceDownload) {
1548                            Download("$gblFsRoot/$relDir/$F");
1549                    } else {
1550                            header("Content-Disposition: attachment; filename=$F" );
1551                            Header("Location: $webRoot".urlpath("$relDir/$F"));
1552                    }
1553                    exit;
1554            case "Ch" :
1555                    StartHTML("(File changes)","All changes chronologicaly...");
1556                    DisplayChangeLog(0);    // all
1557                    EndHTML() ;
1558                    exit;
1559            case "Ch1" :
1560                    StartHTML("(File changes)","Changes to files in last day...");
1561                    DisplayChangeLog(1);
1562                    EndHTML() ;
1563                    exit;
1564            case "I" :
1565                    $F=stripSlashes($F);
1566                    $inc_file="${gblFsRoot}/.${F}.php";
1567                    if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include
1568                    if (!is_readable($inc_file))
1569                            Error("Read access to include file denied",".${F}.php");
1570                    $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
1571                    $title = "You should define \$title variable with page title";
1572                    include($inc_file);
1573                    StartHTML($title, $text) ;
1574                    print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1575                    EndHTML() ;
1576                    exit ;
1577          }          }
1578    
1579          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.56

  ViewVC Help
Powered by ViewVC 1.1.26