/[docman]/docman.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /docman.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by dpavlin, Fri May 12 12:01:08 2000 UTC revision 1.29 by dpavlin, Fri Jan 26 09:32:48 2001 UTC
# Line 34  Line 34 
34  /*             PHP3. Fixed bug which would send you to a non-   */  /*             PHP3. Fixed bug which would send you to a non-   */
35  /*             existent address after file modifications.       */  /*             existent address after file modifications.       */
36    
37    /*
38    
39            This project is now called Directory Manager.
40    
41            For more info, please see web pages at
42            http://www.rot13.org/~dpavlin/docman.html
43    
44            It's relased under GPL by
45            Dobrica Pavlinusic <dpavlin@rot13.org>
46    
47    
48    IMPORTANT INSTALLATION NOTE:
49            deny serving of .* (dot-something) files in web server!
50            Otherwise, uses can access your log files, users and/or
51            deleted files!
52    
53            .htusers is in form:
54            login:Real Name:[md5(loginpassword)|auth_*]:email@host.dom
55    
56    
57    TODO:
58            mixed file/directory output (add type to each entry,
59                    real support for links)
60            access controll
61    
62    */
63    
64  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
65    
66  // TODO : Don't let the file be modified itself. Create a hash of  // TODO : Don't let the file be modified itself. Create a hash of
# Line 44  Line 71 
71    
72  // GLOBAL PARAMETERS  // GLOBAL PARAMETERS
73  // =================  // =================
74  // Make modifications here to suit siteman to your needs  // Make modifications here to suit docman to your needs
75    
76  //      error_reporting(4) ;            // how verbose ?  //      error_reporting(4) ;            // how verbose ?
77    
78            // from where to include auth_*.php modules?
79            $gblIncDir = "/data/docman";
80    
81          // username/password should not be system          // username/password should not be system
82          // usernames/passwords !!          // usernames/passwords !!
83    
84          // your (hashed) username/password here          $gblPw    = "";
85          $gblPw    = "hash_of_your_username_and_password" ;                
86                    $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
87          $gblAuth  = false ;             // use builtin authentication          if (! file_exists($htusers_file)) {
88          $gblHash  = "md5" ;             // hash function to use                  $htusers=fopen($htusers_file,"a+");
89                    fputs($htusers,"# Change owner of $htusers_file to root !!\n");
90                    fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");
91                    fclose($htusers);
92            }
93            $htusers=fopen($htusers_file,"r");
94            while($user = fgetcsv($htusers,255,":")) {
95                    if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
96                            $gblUserName=$user[1];
97                            $gblPw=$user[2];
98                            if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {
99                                    require("$gblIncDir/$gblPw.php");
100                                    if ($gblPw($user)) {
101                                            $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);
102                                    }
103                            }
104                            $gblEmail=$user[3];
105                            continue ;
106                    }
107            }
108            fclose($htusers);
109    
110            // date format
111    //      $gblDateFmt="D, F d, Y";
112            $gblDateFmt="Y-m-d";
113    
114            // time format
115    //      $gblTimeFmt="g:i:sA";
116            $gblTimeFmt="H:i:s";
117    
118            // Number of backup files to keep
119            $gblNumBackups=3;
120    
121            // show red star if newer than ... days
122            $gblModDays=1;
123    
124          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
125          // WingDings font installed on your system          // WingDings font installed on your system
126    
127          $gblIcon = "GifIcon" ;          // MockIcon or GifIcon          $gblIcon="GifIcon";             // MockIcon or GifIcon
128    
129          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
130          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
131    
132          $gblIconLocation = "icons/" ;          $gblIconLocation="/icons/";
133    
134          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
135          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 84  Line 148 
148    
149  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
150    
151          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
152          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
153          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
154  ?>  ?>
155    
156  <HTML>  <HTML>
157  <HEAD>  <HEAD>
158   <TITLE><?php echo $host . " " . $title ?></TITLE>   <TITLE><?= $host . " " . $title ?></TITLE>
159   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">
160   <META NAME="keywords" CONTENT="site manager, web site maintenance">   <META NAME="keywords" CONTENT="site manager, web site maintenance">
161   <META NAME="robots" CONTENT="noindex">   <META NAME="robots" CONTENT="noindex">
162   <META HTTP-EQUIV="expires" CONTENT="0">   <META HTTP-EQUIV="expires" CONTENT="0">
163   <LINK REL="stylesheet" TYPE="text/css"   <LINK REL="stylesheet" TYPE="text/css"
164          HREF="<?php echo $self ?>?STYLE=get">          HREF="<?= $self ?>?STYLE=get">
165  </HEAD>  </HEAD>
166  <BODY BGCOLOR="#FFFFFF">  <BODY BGCOLOR="#FFFFFF">
167   <H3 ALIGN="RIGHT"><?php echo $host ?></H3>   <H3 ALIGN="RIGHT"><?= $host ?></H3>
168  <TABLE BORDER=0 WIDTH="100%"><TR>  <TABLE BORDER=0 WIDTH="100%"><TR>
169   <TD CLASS=INV><?php echo $title ?></TD></TR></TABLE>   <TD CLASS=INV><?= $title ?></TD></TR></TABLE>
170   <P><?php echo $text ?></P>   <P><?= $text ?></P>
171    
172  <?php  <?php
173  } // end function StartHTML  } // end function StartHTML
# Line 115  function EndHTML() { Line 179  function EndHTML() {
179    
180  <HR>  <HR>
181  <P CLASS=FTR>  <P CLASS=FTR>
182  <B><?php echo date("D, F d, Y") ?> -  <B><?= date($GLOBALS[gblDateFmt]) ?> -
183  <?php echo date("g:i:sA") ?></B><BR>ANYPORTAL(php) Site Manager  <?= date($GLOBALS[gblTimeFmt]) ?> -
184  - &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>  <?= $GLOBALS[gblUserName] ?>
185  - &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>  <small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>
186    </B>
187    <BR>ANYPORTAL(php) Site Manager
188    <br><small>
189    &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
190    &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
191    &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
192    </small>
193  </P>  </P>
194  <BR><BR><BR></BODY></HTML>  <BR>
195    <? //include(".debug.inc") ?>
196    <BR><BR></BODY></HTML>
197    
198  <?php  <?php
199  } // end function EndHTML  } // end function EndHTML
# Line 130  function EndHTML() { Line 203  function EndHTML() {
203  function CSS() {  function CSS() {
204  ?>  ?>
205    
206  BODY,TD,P,H1,H2,H3 { font-family:Helvetica,Arial,sans-serif; }  BODY,TD,P,H1,H2,H3 { font-family:Verdana,Helvetica,Arial,sans-serif; }
207  .BLK { color:black; }  .BLK { color:black; }
208  .RED { color:red; }  .RED { color:red; }
209  .TOP { color:red; font-size:70%; } /* table headings */  .TOP { color:red; font-size:70%; } /* table headings */
# Line 164  function DetailPage($fsRoot,$relDir,$fn) Line 237  function DetailPage($fsRoot,$relDir,$fn)
237          $exists   = file_exists($fsPath) ;          $exists   = file_exists($fsPath) ;
238          $ext      = strtolower(strrchr($relPath,".")) ;          $ext      = strtolower(strrchr($relPath,".")) ;
239          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;          $editable = ( $ext=="" || strstr(join(" ",$gblEditable),$ext)) ;
240          $writable = Writeable($fsPath) ;          $writable = is_writeable($fsPath) ;
241            $file_lock = CheckLock($fsPath);
242    
243          if (!$editable && !$exists)          if (!$editable && !$exists)
244                  Error("Creation unsupported for type",$relPath) ;                  Error("Creation unsupported for type",$relPath) ;
245          if (!exists && !Writeable($fsDir) )          if (!exists && !is_writeable($fsDir) )
246                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
247    
248          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
# Line 179  function DetailPage($fsRoot,$relDir,$fn) Line 253  function DetailPage($fsRoot,$relDir,$fn)
253    
254          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;          echo "<H3>" . $relDir . "/" . $fn . "</H3>" ;
255          if ($exists) {  // get file info          if ($exists) {  // get file info
256            $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
257            $fmodified = date("d/M/y G:i:s", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
258            $faccessed = date("d/M/y G:i:s", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
259            echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;
260            echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
261            echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
262            echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;
263            echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;
264            echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
265            echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
266            echo "</PRE>" ;                  echo "</PRE>" ;
267    
268          }          }
269    
270          if ( $editable && ($writable || !$exists) ) {          if ( $editable && ($writable || !$exists) && !$file_lock ) {
271                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
272                  rewind($fh) ;                  rewind($fh) ;
273                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 200  function DetailPage($fsRoot,$relDir,$fn) Line 275  function DetailPage($fsRoot,$relDir,$fn)
275                  $fstr = htmlentities( $fstr ) ;                  $fstr = htmlentities( $fstr ) ;
276  ?>  ?>
277    
278  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
279  <SPAN TITLE="Click [SAVE] to store updated contents.">  <SPAN TITLE="Click [SAVE] to store updated contents.">
280          <B>DOCUMENT CONTENTS</B>          <B>DOCUMENT CONTENTS</B>
281  </SPAN><BR>  </SPAN><BR>
282  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php  <TEXTAREA NAME="FILEDATA" ROWS=18 COLS=70 WRAP="OFF"><?php
283  echo($fstr) ; ?></TEXTAREA>  echo($fstr) ; ?></TEXTAREA>
284  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
285  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
286  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="SAVE">
287  <INPUT TYPE="TEXT" SIZE=48 MAXLENGTH=255 NAME="RELPATH"  <INPUT TYPE="HIDDEN" SIZE=48 MAXLENGTH=255 NAME="RELPATH"
288          VALUE="<?php echo $relPath ; ?>">          VALUE="<?= $relPath ; ?>">
289  <INPUT TYPE="RESET" VALUE="RESET">  <br>
290    <INPUT TYPE="RESET" VALUE="UNDO ALL CHANGES">
291  <INPUT TYPE="SUBMIT" VALUE="SAVE">  <INPUT TYPE="SUBMIT" VALUE="SAVE">
292  </FORM>  </FORM>
293    
294  <?php  <?php
295          }          }
296          else if ( strstr( join(" ",$gblImages), $ext ) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
297            $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
298            $tstr  = "<IMG SRC=\"". $relPath . "\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
299            $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
300            $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
301            echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
302                    echo $tstr ;
303          }          }
304    
305  ?>  ?>
306    
307  <FORM ACTION="<?php echo $self ; ?>" METHOD="POST">  <FORM ACTION="<?= $self ; ?>" METHOD="POST">
308  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ; ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ; ?>">
309  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?php echo $fn ; ?>">  <INPUT TYPE="HIDDEN" NAME="FN" VALUE="<?= $fn ; ?>">
310  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL"><BR>
311    
312  <?php  <?php
313    
314            if ($file_lock) {
315    ?>
316    <hr>
317    <SPAN TITLE="Check OK and click UNLOCK to remove lock on file.">
318    <B>OK TO FORCE LOCK REMOVAL ON "<?= $fn ; ?>" HELD BY <?= $file_lock ?>? </B></SPAN>
319    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
320    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="UNLOCK">
321    <?
322            } // file_lock
323    
324            if (substr($fn,0,4) == ".del") {
325                    $action="UNDELETE";
326                    $desc="undelete previously deleted file";
327            } else {
328                    $action="DELETE";
329                    $desc="delete";
330            }
331    
332          if ($exists && $writable) {          if ($exists && $writable) {
333  ?>  ?>
334    
335  <HR><SPAN TITLE="Check OK and click [DELETE] to delete.">  <HR>
336  <B>OK TO DELETE "<?php echo $fn ; ?>"? </B></SPAN>  <a name="undelete">
337    <SPAN TITLE="Check OK and click [<?= $action ?>] to <?= $desc ?>.">
338    <B>OK TO <?= $action ?> "<?= $fn ; ?>"? </B></SPAN>
339    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
340    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="<?= $action ?>">
341    
342    <HR>
343    <a name="rename">
344    <SPAN TITLE="Check OK and click [RENAME] to rename.">
345    <B>OK TO RENAME "<?= $fn ; ?>" TO
346    <INPUT TYPE="TEXT" SIZE=24 MAXLENGTH=255 NAME="NEWNAME" VALUE="<?= $fn ?>">
347    ? </B></SPAN>
348  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">  <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
349  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="RENAME">
350    
351    <?php
352            }       // exists && writable
353    ?>
354    <HR>
355    <a name="note">
356    <B>NOTE FOR "<?= $fn ; ?>":
357    <INPUT TYPE="TEXT" SIZE=50 MAXLENGTH=255 NAME="NOTE" VALUE="<?= ReadNote($fsPath) ?>">
358    </B></SPAN>
359    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="NOTE">
360    
361    </FORM>
362    
363  <?php  <?php
364    
365            $name=basename("$fsDir/$fn");
366            $logname=dirname("$fsDir/$fn")."/.log/$name";
367            $bakdir=dirname("$fsDir/$fn")."/.bak";
368            if (file_exists($logname)) {
369                    $log=fopen($logname,"r");
370                    $cl1=" class=LST"; $cl2="";
371                    $logarr = array();
372                    while($line = fgetcsv($log,255,"\t")) {
373                            $cl=$cl1; $cl1=$cl2; $cl2=$cl;
374                            array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
375                    }
376                    fclose($log);
377                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
378                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
379                    while ($e = array_shift($logarr)) {
380                            if (strstr($e[4],"upload")) {
381                                    if (file_exists("$bakdir/$bakcount/$name")) {
382                                            $e[4]="<a href=\"".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
383                                    }
384                                    $bakcount++;
385                            }
386                            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";
387                    }
388                    print "</table>";
389          }          }
390          echo "</FORM>" ;  
391          EndHTML() ;          EndHTML() ;
392    
393  } // end function DetailPage  } // end function DetailPage
# Line 472  function GifIcon($txt) { Line 617  function GifIcon($txt) {
617          case "blank" :          case "blank" :
618                  $d = "blank.gif" ;                  $d = "blank.gif" ;
619                  break ;                  break ;
620            case "checkout":
621                    $d = "box2.gif";
622                    break;
623            case "checkin":
624                    $d = "hand.up.gif";
625                    break;
626            case "locked":
627                    $d = "screw2.gif";
628                    break;
629            case "note":
630                    $d = "quill.gif";
631                    break;
632          default :          default :
633                  $d = "generic.gif" ;                  $d = "generic.gif" ;
634          }          }
# Line 483  function GifIcon($txt) { Line 640  function GifIcon($txt) {
640    
641  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
642    
643          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays ;
644    
645          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
646          $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
647                    $webRoot  = "https://" . $GLOBALS["HTTP_HOST"] ;
648            } else {
649                    $webRoot  = "http://" . $GLOBALS["HTTP_HOST"] ;
650            }
651          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir    = $fsRoot . $relDir . "/" ; // current directory
652    
653          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
# Line 495  function Navigate($fsRoot,$relDir) { Line 656  function Navigate($fsRoot,$relDir) {
656          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
657                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
658          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
659                  if ( $item == ".." || $item == "." ) continue ;                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;
660                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
661                          $dirList[] = $item ;                          $dirList[] = $item ;
662                  }                  } else if ( is_file($fsDir . $item) ) {
                 else if ( is_file($fsDir . $item) ) {  
663                          $fileList[] = $item ;                                    $fileList[] = $item ;          
664                  }                  } else if ( is_link($fsDir . $item) ) {
665                  else {                          $dirList[] = $item ;
666                    } else {
667                    // unknown file type                    // unknown file type
668                    // $text = "Could not determine file type of " ;                    // $text = "Could not determine file type of " ;
669                    // Error("File Error", $text.$relDir."/".$item) ;                    // Error("File Error", $text.$relDir."/".$item) ;
# Line 510  function Navigate($fsRoot,$relDir) { Line 671  function Navigate($fsRoot,$relDir) {
671                  }                  }
672          }          }
673          closedir($dir) ;          closedir($dir) ;
674    
675            // scan deleted files
676            if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
677                    while ($item = readdir($dir)) {
678                            if ( substr($item,0,1) == "." ) continue ;
679                            $fileList[] = ".del/$item" ;            
680                    }
681                    closedir($dir) ;
682            }
683    
684          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;          $emptyDir = ! (sizeof($dirList) || sizeof($fileList)) ;
685    
686          // start navigation page          // start navigation page
687          $text  = "Use this page to add, delete or " ;          $text  = "Use this page to add, delete";
688          $text .= "revise files on this web site." ;          if (! isset($show_deleted)) {
689                    $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
690            }
691            $text .= " or revise files on this web site." ;
692            $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>.";
693          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
694    
695          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 527  function Navigate($fsRoot,$relDir) { Line 701  function Navigate($fsRoot,$relDir) {
701                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
702  ?>  ?>
703    
704  <TR><TD><?php echo $gblIcon("up") ?></TD><TD COLSPAN=4 CLASS=LST>  <TR><TD><?= $gblIcon("up") ?></TD><TD COLSPAN=5 CLASS=LST>
705  <A HREF="<?php echo $self ?>?D=<?php echo urlencode($parent) ?>">  <A HREF="<?= $self ?>?D=<?= urlencode($parent) ?>">
706  <B><?php echo $parent ?></B></A></TD></TR>  <B><?= $parent ?></B></A></TD></TR>
707    
708  <?php  <?php
709          }          }
# Line 539  function Navigate($fsRoot,$relDir) { Line 713  function Navigate($fsRoot,$relDir) {
713                  sort($dirList) ;                  sort($dirList) ;
714  ?>  ?>
715    
716  <TR><TD></TD><TD COLSPAN=4 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>  <TR><TD></TD><TD COLSPAN=5 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>
717    
718  <?php  <?php
719                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
# Line 549  function Navigate($fsRoot,$relDir) { Line 723  function Navigate($fsRoot,$relDir) {
723                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
724  ?>  ?>
725    
726  <TR><TD><?php echo $gblIcon("fldr") ?></TD>  <TR><TD><?= $gblIcon("fldr") ?></TD>
727  <TD COLSPAN=4 CLASS=LST><?php echo $tstr ?></TD></TR>  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>
728    
729  <?php  <?php
730                  }  // iterate over dirs                  }  // iterate over dirs
731          }  // end if no dirs          }  // end if no dirs
732  ?>  ?>
733    
734  <TR><TD></TD><TD COLSPAN=4><HR><B><?php echo $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
735  </B></TD></TR>  </B></TD></TR>
736  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>
737  <TD><?php echo $gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
738    <TD CLASS=TOP>NOTE</TD>
739  <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>
740    
741  <?php  <?php
742          if (sizeof($fileList) > 0) {          if (sizeof($fileList) > 0) {
743            sort($fileList) ;            sort($fileList) ;
744            while (list($key,$file) = each($fileList)) {              while (list($key,$file) = each($fileList)) {  
745              $path = $fsDir."/".$file ;                  $path = $fsDir."/".$file ;
746              $mod  = filemtime($path) ;                  $mod  = filemtime($path) ;
747              $sz   = filesize($path) ;                  $sz   = filesize($path) ;
748    
749              if ($sz >= 10240) {                  if ($sz >= 10240) {
750                $sz = (int)(($sz+1023)/1024) . " k" ;                          $sz = (int)(($sz+1023)/1024) . " k" ;
751              }                  } else {
752              else {                          $sz .= " " ;
753                $sz .= " " ;                  } // end size
754              } // end size  
755                    $a = $b = "" ;
756              $a = $b = "" ;  
757                    $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
758              if ( ($mod + 30*86400) > time() ) {  
759                $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                  if ( ($mod + $gblModDays*86400) > time() ) {
760                $a .= " than 30 days\"> * </SPAN>" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
761              }                          $a .= " than $gblModDays days\"> * </SPAN>" ;
762                    }
763              $tstr = $webRoot . $relDir . "/" . $file ;  
764              $tstr  = "<A HREF=\"" . $tstr . "\">" ;                  $file_lock=CheckLock($path);
765              $tstr .= $file . "</A>" . $a ;  
766                    $file_url_html="<A HREF=\"$self?A=V&F=".urlencode($file);
767              $ext = strtolower(strrchr($file,".")) ;                  $file_url_html.="&D=".urlencode($relDir);
768              if ( $ext=="" ||                  $file_url_html.="\" TITLE=\"View file\">" ;
769                   strstr(join(" ",$gblEditable),$ext) )  
770              {                    if (substr($file,0,5) != ".del/") {
771                $b  = "<A HREF=\"" . $self . "?A=C&F=" ;                          $file_url_html .= $file . "</A>" . $a ;
772                $b .= urlencode($file) . "&D=" . urlencode($relDir) ;                  } else {
773                $b .= "\" TITLE=\"List contents\">" ;                          $file_url_html .= substr($file,5,strlen($file)-5) . "</a> <SPAN CLASS=RED TITLE=\"deleted\"> <a href=\"$info_url#undelete\">deleted</a> </span>";
774                $b .= $gblIcon("view") . "</A>" ;                  }
775              }  
776                    $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($path);
777    
778                    $ext = strtolower(strrchr($file,".")) ;
779    
780                    if ($file_lock) {
781                            if ($file_lock == $GLOBALS[gblUserName]) {
782                                    $b.="<A HREF=\"$self?A=Ci&F=".urlencode($file);
783                                    $b.="&D=".urlencode($relDir);
784                                    $b.="\" TITLE=\"Checkin (update) file on server\">" ;
785                                    $file_url_html=$b;
786                                    $b.=$gblIcon("checkin")."</A>" ;
787                                    $b.= $gblIcon("blank");
788                                    $file_url_html.="$file</a> $a";
789                                    $note_html = $gblIcon("blank")."<b>Please check-in (update) this file</b>";
790                            } else {
791                                    $b = $gblIcon("locked");
792                                    $b.= $gblIcon("blank");
793                                    $note_html = $gblIcon("blank")."<b>File locked by $file_lock</b>";
794                                    $file_url_html = "$file $a";
795                            }
796                    } else {
797                            $b.="<A HREF=\"$self?A=Co&F=".urlencode($file);
798                            $b.="&D=".urlencode($relDir);
799                            $b.="\" TITLE=\"Checkout file for edit\">" ;
800                            $b.=$gblIcon("checkout")."</A>" ;
801    
802                            if ( $ext=="" || strstr(join(" ",$gblEditable),$ext) ) {  
803                                    $b.="<A HREF=\"$self?A=C&F=".urlencode($file);
804                                    $b.="&D=".urlencode($relDir);
805                                    $b.="\" TITLE=\"List contents\">" ;
806                                    $b.=$gblIcon("view")."</A>" ;
807                            } else {
808                                    $b.= $gblIcon("blank");
809                            }
810                    }
811    
812    
813  ?>  ?>
814    
815  <TR><TD>  <TR><TD>
816  <A HREF="<?php echo $self ?>?A=E&F=<?php echo urlencode($file)  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
817  ?>&D=<?php echo urlencode($relDir) ?>" TITLE="View/Edit">  <?= $gblIcon($ext) ?></A></TD>
818  <?php echo $gblIcon($ext) ?></A></TD>  <TD CLASS=LST><?= $file_url_html ?></TD>
819  <TD CLASS=LST><?php echo $tstr ?></TD>  <TD CLASS=LST ALIGN=center><?= $b ?></TD>
820  <TD CLASS=LST ALIGN=center><?php echo $b ?></TD>  <TD CLASS=LST ALIGN=left><?= $note_html ?></TD>
821  <TD CLASS=LST><?php echo date("d/M/y G:i:s",$mod) ?></TD>  <TD CLASS=LST><?= date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]",$mod) ?></TD>
822  <TD CLASS=LST><?php echo $sz ?>Bytes</TD></TR>  <TD CLASS=LST><?= $sz ?>Bytes</TD></TR>
823    
824  <?php  <?php
825            }  // iterate over files            }  // iterate over files
826          }  // end if no files          } else {  // end if no files
827    ?>
828     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
829      No files in this directory
830     </TD></TR>
831    <?
832            }
833    
834          if ($emptyDir) {          if ($emptyDir) {
835  ?>  ?>
836    
837  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
838   <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>   <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>
839    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">    <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
840    OK TO DELETE THIS EMPTY FOLDER?    OK TO DELETE THIS EMPTY FOLDER?
841    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">    <INPUT TYPE="CHECKBOX" NAME="CONFIRM">
842    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">    <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="DELETE">
# Line 630  function Navigate($fsRoot,$relDir) { Line 847  function Navigate($fsRoot,$relDir) {
847          } // end if emptyDir          } // end if emptyDir
848  ?>  ?>
849    
850  <TR><TD></TD><TD COLSPAN=4><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
851    
852    <?
853    if (file_exists(".info.inc")) {
854            print "<TR><TD></TD><TD COLSPAN=5>";
855            include(".info.inc");
856            print "</TD></TR>
857            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
858    }
859    ?>
860    
861  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
862  <TR><TD></TD><TD COLSPAN=4 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
863   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-   <INPUT TYPE="RADIO" NAME="T" VALUE="D" CHECKED>DIRECTORY -OR-
864   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;   <INPUT TYPE="RADIO" NAME="T" VALUE="F">FILE : &nbsp;&nbsp;
865   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
866   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
867   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
868   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>
869   <NOBR>OR <A HREF="<?php echo $self   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
         ?>?A=U&D=<?php echo urlencode($relDir) ?>">UPLOAD</A> A FILE  
870   </NOBR>   </NOBR>
871  </TD></TR>  </TD></TR>
872  </FORM>  </FORM>
# Line 653  function Navigate($fsRoot,$relDir) { Line 878  function Navigate($fsRoot,$relDir) {
878    
879  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
880    
881  function UploadPage($fsRoot, $relDir) {  function UploadPage($fsRoot, $relDir, $filename="") {
882    
883          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
884          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 661  function UploadPage($fsRoot, $relDir) { Line 886  function UploadPage($fsRoot, $relDir) {
886    
887  <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>
888  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
889   ACTION="<?php echo $self ?>">   ACTION="<?= $self ?>">
890  DESTINATION DIRECTORY:<B><?php echo " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
891    <? if (isset($filename) && $filename!="") { ?>
892    <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
893    <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
894    <? } ?>
895  <P>PATHNAME OF LOCAL FILE<BR>  <P>PATHNAME OF LOCAL FILE<BR>
896  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>">  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
897  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">  <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="UPLOAD">
898  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>  <INPUT SIZE=30 TYPE="FILE" NAME="FN"></P>
899  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>  <P><INPUT TYPE="SUBMIT" VALUE="UPLOAD"></P>
900  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>  <P>If the <B>[BROWSE...]</B> button is not displayed,<BR>
901  you must upgrade to an RFC1867-compliant browser.</P>  you must upgrade to an RFC1867-compliant browser.</P>
902  <P>Your browser:<BR><?php echo $GLOBALS["HTTP_USER_AGENT"] ?></P>  <P>Your browser:<BR><?= $GLOBALS["HTTP_USER_AGENT"] ?></P>
903  </FORM>  </FORM>
904  </TD></TR>  </TD></TR>
905  <TR><TD></TD><TD>  <TR><TD></TD><TD>
906  <FORM METHOD="POST" ACTION="<?php echo $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
907  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?php echo $relDir ?>"><BR>  <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>"><BR>
908  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">  <INPUT TYPE="SUBMIT" NAME="POSTACTION" VALUE="CANCEL">
909  </FORM>  </FORM>
910  </TD></TR></TABLE></P>  </TD></TR></TABLE></P>
# Line 694  function Error($title,$text="") { Line 923  function Error($title,$text="") {
923    
924  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
925    
926  function Writeable($path) {  function NoEntry() {
         // fix by -mat- filid brandy, brandy@ecrc.de, 07/JUL/99  
927    
928          clearstatcache ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
929          $perms = @fileperms($path) ;          $pw   = $GLOBALS["PHP_AUTH_PW"] ;      
930          $owner = @fileowner($path) ;          $self = $GLOBALS["PHP_SELF"] ;
         exec("id",$id) ;  
         eregi( "^uid=([0-9]*)",$id[0], $regs) ;  
         $apacheuid = $regs[1] ;  
         $perms = 0777 & $perms ;  
         if ( $apacheuid != $owner ) {  
                 return (06 == (06 & $perms)) ?  1 : 0 ;  
         }  
         else {  
                 return (0600 == (0600 & $perms)) ? 1 : 0 ;  
         }  
   
 } // end function Writable  
931    
932  //////////////////////////////////////////////////////////////////          $title = "(401 Unauthorized)" ;
933            $text  = "No trespassing !" ;
934            StartHTML($title,$text) ;
935    
 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>" ;  
936          EndHTML() ;          EndHTML() ;
937          exit ;          exit ;
938    }
939    
940    //////////////////////////////////////////////////////////////////
941    
942    function LogIt($target,$msg) {
943    
944            $dir=dirname($target);
945            if (! file_exists($dir."/.log")) {
946                    mkdir($dir."/.log",0700);
947            }
948            $file=basename($target);
949    
950            $log=fopen("$dir/.log/$file","a+");
951            fputs($log,date("$GLOBALS[gblDateFmt]\t$GLOBALS[gblTimeFmt]").
952                    "\t$GLOBALS[gblUserName]\t$msg\n");
953            fclose($log);
954    
955    }
956    
 } // end function CreateHash  
957    
958  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
959    
960  function NoEntry() {  function WriteNote($target,$msg) {
961    
962          $user = $GLOBALS["PHP_AUTH_USER"] ;          $target=stripSlashes($target);
963          $pw   = $GLOBALS["PHP_AUTH_PW"] ;                $dir=dirname($target);
964          $self = $GLOBALS["PHP_SELF"] ;          if (! file_exists($dir."/.note")) {
965                    mkdir($dir."/.note",0700);
966            }
967            $file=basename($target);
968    
969          $title = "(401 Unauthorized)" ;          $note=fopen("$dir/.note/$file","w");
970          $text  = "No trespassing !" ;          fputs($note,"$msg\n");
971          StartHTML($title,$text) ;          fclose($note);
 ?>  
972    
973  <FORM ACTION="<?php echo $self ?>?HASH=create" METHOD="POST">          Logit($target,"added note $msg");
 <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>  
974    
975  <?php  }
976          EndHTML() ;  
977          exit ;  function ReadNote($target) {
978    
979            $target=stripSlashes($target);
980            $dir=dirname($target);
981            $file=basename($target);
982            $msg="";
983            if (file_exists($dir."/.note/$file")) {
984                    $note=fopen("$dir/.note/$file","r");
985                    $msg=fgets($note,4096);
986                    fclose($note);
987            }
988            return StripSlashes($msg);
989    
990    }
991    
992    //////////////////////////////////////////////////////////////////
993    
994    function MoveTo($source,$folder) {
995    
996            $source=stripSlashes($source);
997            $file=basename($source);
998            if (! file_exists($folder)) {
999                    mkdir($folder,0700);
1000            }
1001            if (file_exists($source)) {
1002                    rename($source,"$folder/$file");
1003            }
1004    }
1005    
1006    //////////////////////////////////////////////////////////////////
1007    
1008    function Lock($target) {
1009    
1010            $target=stripSlashes($target);
1011            $dir=dirname($target);
1012            if (! file_exists($dir."/.lock")) {
1013                    mkdir($dir."/.lock",0700);
1014            }
1015            $file=basename($target);
1016    
1017            if (file_exists("$dir/.lock/$file")) {
1018                    Logit($target,"attempt to locked allready locked file!");
1019            } else {
1020                    $lock=fopen("$dir/.lock/$file","w");
1021                    fputs($lock,"$GLOBALS[gblUserName]\n");
1022                    fclose($lock);
1023    
1024                    Logit($target,"file locked");
1025            }
1026    
1027    }
1028    
1029    function CheckLock($target) {
1030    
1031            $target=stripSlashes($target);
1032            $dir=dirname($target);
1033            $file=basename($target);
1034            $msg=0;
1035            if (file_exists($dir."/.lock/$file")) {
1036                    $lock=fopen("$dir/.lock/$file","r");
1037                    $msg=fgets($lock,4096);
1038                    fclose($lock);
1039            }
1040            return chop($msg);
1041    
1042    }
1043    
1044    function Unlock($target) {
1045    
1046            $target=stripSlashes($target);
1047            $dir=dirname($target);
1048            $file=basename($target);
1049            if (file_exists($dir."/.lock/$file")) {
1050                    unlink("$dir/.lock/$file");
1051                    Logit($target,"file unlocked");
1052            } else {
1053                    Logit($target,"attempt to unlocked non-locked file!");
1054            }
1055    
1056    }
1057    
1058    //////////////////////////////////////////////////////////////////
1059    
1060    function urlpath($url) {
1061            $url=urlencode(StripSlashes("$url"));
1062            $url=str_replace("%2F","/",$url);
1063            $url=str_replace("+","%20",$url);
1064            return($url);
1065    }
1066    
1067    //////////////////////////////////////////////////////////////////
1068    
1069    function safe_rename($from,$to) {
1070            if (file_exists($from) && is_writable(dirname($to))) {
1071                    rename($from,$to);
1072            }
1073    }
1074    
1075    //////////////////////////////////////////////////////////////////
1076    
1077    // recursivly delete directory
1078    
1079    function rrmdir($dir) {
1080            $handle=opendir($dir);
1081            while ($file = readdir($handle)) {
1082                    if ($file != "." && $file != "..") {
1083                            if (is_dir("$dir/$file"))
1084                                    rrmdir("$dir/$file");
1085                            else
1086                                    if (! @unlink("$dir/$file")) return(0);
1087                    }
1088            }
1089            closedir($handle);
1090            return @rmdir($dir);
1091    }
1092    
1093    //////////////////////////////////////////////////////////////////
1094    
1095    function ChangeLog($target,$msg) {
1096    
1097            global $gblFsRoot;
1098            $log=fopen("$gblFsRoot/.changelog","a+");
1099            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1100                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1101            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1102            fclose($log);
1103    
1104    }
1105    
1106    function DisplayChangeLog($day) {
1107    
1108            global $gblFsRoot;
1109            if (!file_exists("$gblFsRoot/.changelog")) return;
1110            $log=fopen("$gblFsRoot/.changelog","r");
1111            $logarr = array();
1112            while($line = fgetcsv($log,255,"\t")) {
1113                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1114                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1115                    }
1116            }
1117            fclose($log);
1118            $cl1=" class=LST"; $cl2="";
1119            print "<table border=0 width=100%>\n";
1120            while ($e = array_shift($logarr)) {
1121                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1122                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1123                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1124                    $dir = dirname($e[1]);
1125                    $file = basename($e[1]);
1126                    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";
1127            }
1128            print "</table>";
1129            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1130  }  }
1131    
1132  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 773  the source<BR>of this file.<BR><BR> Line 1137  the source<BR>of this file.<BR><BR>
1137  // local functions : begin with capital letters  // local functions : begin with capital letters
1138  // global constants: begin with gbl  // global constants: begin with gbl
1139    
1140          $gblFilePerms = "644" ;         // default for new files          $gblFilePerms = 0640 ;         // default for new files
1141          $gblDirPerms  = 0755 ;          // default for new dirs          $gblDirPerms  = 0750 ;          // default for new dirs
1142    
1143          // phpinfo() ;          // phpinfo() ;
1144          // exit ;          // exit ;
# Line 782  the source<BR>of this file.<BR><BR> Line 1146  the source<BR>of this file.<BR><BR>
1146          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1147          // creation if password not yet set.          // creation if password not yet set.
1148          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
         if ($HASH != "") {  
                 CreateHash($USER, $PW) ;  
                 exit ;  
         }  
1149    
1150          // authentication if $gblAuth == true          // authentication failure
1151          if ( $gblAuth &&          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1152               $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ) {                  isset($relogin) && $gblPw == $relogin ) {
1153                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1154                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1155                  NoEntry() ;                  NoEntry() ;
1156                  exit ;                  exit ;
# Line 813  the source<BR>of this file.<BR><BR> Line 1173  the source<BR>of this file.<BR><BR>
1173          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1174    
1175          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1176          // i.e. /siteman          // i.e. /docman
1177    
1178          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1179          // i.e. /home/httpd/html/siteman          // i.e. /home/httpd/html/docman
1180    
1181          $gblFsRoot = substr($fsScriptDir,0,          // start on server root
1182            strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1183            // or on script root
1184            $gblFsRoot = $fsScriptDir;
1185          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1186    
1187          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1188          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1189            
1190            $FN=stripSlashes($FN);
1191    
1192          switch ($POSTACTION) {          switch ($POSTACTION) {
1193          case "UPLOAD" :          case "UPLOAD" :
1194                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1195                  if (strstr($FN_name,"/"))                  if (strstr($FN_name,"/"))
1196                          Error("Non-conforming filename") ;                          Error("Non-conforming filename") ;
1197                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1198                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1199                  $source = $FN ;                  $source = $FN ;
1200                  $target = $fsDir . "/" . $FN_name ;                  if (! file_exists($source)) {
1201                  exec("cp $source $target") ;                          Error("You must select file with browse to upload it!");
1202                  exec("chmod $gblFilePerms $target") ;                  }
1203                    if (! isset($FILENAME)) {       // from update file
1204                            $target = "$fsDir/$FN_name" ;
1205                    } else {
1206                            $target = "$fsDir/$FILENAME";
1207                    }
1208    
1209                    // backup old files first
1210                    $dir=dirname($target);
1211                    if (! file_exists($dir."/.bak")) {
1212                            mkdir($dir."/.bak",0700);
1213                    }
1214                    if (! file_exists($dir."/.bak/$GLOBALS[gblNumBackups]")) {
1215                            mkdir($dir."/.bak/$GLOBALS[gblNumBackups]",0700);
1216                    }
1217                    $file=basename($target);
1218                    for($i=$GLOBALS[gblNumBackups]-1;$i>0;$i--) {
1219                            MoveTo("$dir/.bak/$i/$file","$dir/.bak/".($i+1)."/");
1220                    }
1221                    MoveTo($target,$dir."/.bak/1/");
1222    
1223                    copy($source,$target) ;
1224                    chmod($target,$gblFilePerms) ;
1225                  clearstatcache() ;                  clearstatcache() ;
1226                    Logit($target,"uploaded");
1227                    if (isset($FILENAME)) {
1228                            Unlock($target);
1229                    }
1230                    ChangeLog($target,"updated");
1231                  break ;                  break ;
1232    
1233          case "SAVE" :          case "SAVE" :
1234                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1235                  $writable = Writeable($path) ;                  $path=stripSlashes($path);
1236                  $legaldir = Writeable(dirname($path)) ;                  $writable = is_writeable($path) ;
1237                    $legaldir = is_writeable(dirname($path)) ;
1238                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
1239  // check for legal extension here as well  // check for legal extension here as well
1240                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1241                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1242                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1243                    $FILEDATA=stripSlashes($FILEDATA);
1244                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1245                  fclose($fh) ;                  fclose($fh) ;
1246                  clearstatcache() ;                  clearstatcache() ;
1247                    Logit($path,"saved changes");
1248                    ChangeLog($path,"saved changes");
1249                  break ;                  break ;
1250    
1251          case "CREATE" :          case "CREATE" :
1252                  // we know $fsDir exists                  // we know $fsDir exists
1253                  if (!Writeable($fsDir)) Error("Write denied",$relDir) ;                  if ($FN == "") break;           // no filename!
1254                    if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
1255                  $path = $fsDir . "/" . $FN ;  // file or dir to create                  $path = $fsDir . "/" . $FN ;  // file or dir to create
1256                  $relPath = $relDir . "/" . $FN ;                  $relPath = $relDir . "/" . $FN ;
1257                  switch ( $T ) {                  switch ( $T ) {
1258                  case "D" :  // create a directory                  case "D" :  // create a directory
1259                    if ( ! @mkdir($path,$gblDirPerms) )                          if ( ! @mkdir($path,$gblDirPerms) )
1260                      Error("Mkdir failed",$relPath) ; // eg. if it exists                                  Error("Mkdir failed",$relPath) ; // eg. if it exists
1261                    clearstatcache() ;                          clearstatcache() ;
1262                    break ;                          break ;
1263                  case "F" :  // create a new file                  case "F" :  // create a new file
1264  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1265  // better keep it here altogether  // better keep it here altogether
1266  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1267                    if ( file_exists($path) && !Writable($path) )                          if ( file_exists($path) && !is_writable($path) )
1268                      Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1269                    $tstr = $PHP_SELF . "?A=E&D=" . $relDir . "&F=" . $FN ;                          $fh = fopen($path, "w+") ;
1270                    header("Location: " . $tstr) ;                          if ($fh) {
1271                    exit ;                                  fputs($fh,"\n");
1272                                    fclose($fh) ;
1273                                    LogIt($path,"file created");
1274                            } else {
1275                                    Error("Creation of file $relPath failed -- $path");
1276                            }
1277                            $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1278                            header("Location: " . $tstr) ;
1279                            ChangeLog($target,"created");
1280                            exit ;
1281                  }                  }
1282                  break ;                  break ;
1283    
# Line 883  the source<BR>of this file.<BR><BR> Line 1288  the source<BR>of this file.<BR><BR>
1288                  $tstr .= "insufficient privileges: " ;                  $tstr .= "insufficient privileges: " ;
1289    
1290                  if ( $FN != "") {  // delete file                  if ( $FN != "") {  // delete file
1291                    $path =  $fsDir . "/" . $FN ;                          $path =  $fsDir . "/" . $FN ;
1292                    if ( ! @unlink($path) ) {                  
1293                      Error("File delete failed", $tstr . $path) ;                          $dir=dirname($path);
1294                      exit ;                          $file=basename($path);
1295                    }                                              if (! file_exists("$dir/.del")) {
1296                                    mkdir("$dir/.del",0700);
1297                            }
1298    
1299    //                      if ( ! @unlink($path) ) {
1300                            if ( ! rename($path,"$dir/.del/$file") ) {
1301                                    Error("File delete failed", $tstr . $path) ;
1302                                    Logit($path,"file delete failed");
1303                                    exit ;
1304                            } else {
1305                                    Logit($path,"file deleted");
1306                                    MoveTo("$dir/.log/$file","$dir/.del/.log/");
1307                                    MoveTo("$dir/.note/$file","$dir/.del/.note/");
1308                                    MoveTo("$dir/.lock/$file","$dir/.del/.lock/");
1309                            }
1310                  }                  }
1311                  else {  // delete directory                  else {  // delete directory
1312                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1313                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1314                    }                    }
1315                    else {                    else {
# Line 899  the source<BR>of this file.<BR><BR> Line 1318  the source<BR>of this file.<BR><BR>
1318                  }                  }
1319                  break ;                  break ;
1320    
1321            case "UNDELETE" :  
1322                    if ( $CONFIRM != "on" ) break ;
1323    
1324                    if (substr($FN,0,4) != ".del") break ;
1325                    $file=substr($FN,4,strlen($FN)-4);
1326    
1327                    Logit("$fsDir/.del/$file","undeleted");
1328                    MoveTo("$fsDir/.del/$file","$fsDir/");
1329                    MoveTo("$fsDir/.del/.log/$file","$fsDir/.log/");
1330                    MoveTo("$fsDir/.del/.note/$file","$fsDir/.note/");
1331                    MoveTo("$fsDir/.del/.lock/$file","$fsDir/.lock/");
1332    
1333                    break ;
1334    
1335            case "RENAME" :  
1336                    if ( $CONFIRM != "on" ) break ;
1337    
1338                    Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1339                    safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");
1340                    safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1341                    safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1342                    safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1343                    for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1344                            safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
1345                    }
1346    
1347                    break ;
1348    
1349            case "NOTE" :  
1350                    WriteNote("$fsDir/$FN","$NOTE");
1351                    break ;
1352    
1353            case "UNLOCK" :  
1354                    if ( $CONFIRM != "on" ) break ;
1355                    Unlock("$fsDir/$FN");
1356                    break ;
1357    
1358          default :          default :
1359                  // user hit "CANCEL" or undefined action                  // user hit "CANCEL" or undefined action
1360          }          }
# Line 914  the source<BR>of this file.<BR><BR> Line 1370  the source<BR>of this file.<BR><BR>
1370          // $A=U : upload to path given in $D          // $A=U : upload to path given in $D
1371          // $A=E : display detail of file $D/$F and edit          // $A=E : display detail of file $D/$F and edit
1372          // $A=C : display code in file $D/$F          // $A=C : display code in file $D/$F
1373            // $A=Co : checkout file $D/$F
1374            // $A=Ci : checkin file $D/$F
1375            // $A=V : view file (do nothing except log)
1376          // default : display directory $D          // default : display directory $D
1377            
1378          switch ($A) {          switch ($A) {
1379          case "U" :          case "U" :
1380                  // upload to $relDir                  // upload to $relDir
1381                  if (!Writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1382                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1383                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1384                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1385                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1386                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1387                  EndHTML() ;                  EndHTML() ;
1388                  exit ;                  exit ;
1389          case "E" :          case "E" :
1390                    $F=stripSlashes($F);
1391                  // detail of $relDir/$F                  // detail of $relDir/$F
1392                  DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1393                  exit ;                  exit ;
1394          case "C" :          case "C" :
1395                    $F=stripSlashes($F);
1396                  // listing of $relDir/$F                  // listing of $relDir/$F
1397                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1398                  exit ;                  exit ;
1399            case "Co" :
1400                    // checkout
1401                    Lock("$gblFsRoot/$relDir/$F");
1402                    header("Content-Disposition: attachment; filename=$F" );
1403                    Header("Location: ".urlpath("$relDir/$F"));
1404                    exit;
1405            case "Ci" :
1406                    $F=stripSlashes($F);
1407                    // upload && update to $relDir
1408                    if (!is_writeable($gblFsRoot . $relDir))
1409                            Error("Write access denied",$relDir) ;
1410                    $text  = "Use this page to update a single " ;
1411                    $text .= "file to <B>$HTTP_HOST</B>." ;
1412                    StartHTML("(Update file Page)", $text) ;
1413                    UploadPage($gblFsRoot, $relDir, $F) ;
1414                    EndHTML() ;
1415                    exit ;
1416            case "V" :
1417                    // view
1418                    LogIt("$gblFsRoot/$relDir/$F","viewed");
1419                    header("Content-Disposition: attachment; filename=$F" );
1420                    Header("Location: ".urlpath("$relDir/$F"));
1421                    exit;
1422            case "Ch" :
1423                    StartHTML("(File changes)","All changes chronologicaly...");
1424                    DisplayChangeLog(0);    // all
1425                    EndHTML() ;
1426                    exit;
1427            case "Ch1" :
1428                    StartHTML("(File changes)","Changes to files in last day...");
1429                    DisplayChangeLog(1);
1430                    EndHTML() ;
1431                    exit;
1432          }          }
1433    
1434          // default: display directory $relDir          // default: display directory $relDir

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

  ViewVC Help
Powered by ViewVC 1.1.26