/[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.20 by dpavlin, Wed Sep 13 08:08:22 2000 UTC revision 1.43 by dpavlin, Wed Jun 20 10:29:19 2001 UTC
# Line 35  Line 35 
35  /*             existent address after file modifications.       */  /*             existent address after file modifications.       */
36    
37  /*  /*
         2000-07-25 Dobrica Pavlinusic <dpavlin@rot13.org>  
38    
39          nuked exec calls (unsecure)          This project is now called Directory Manager.
         nuked writeable function (replaced by php is_writeable)  
         added support for https (tested with apache+mod_ssl)  
         added users file  
         date format user-selectable  
         cycle backup files in bak directory  
         support links as directoryes (for now)  
         support of file history logging  
         undelete capabilities (delete moves to .del directory)  
40    
41          2000-07-26 DbP          For more info, please see web pages at
42            http://www.rot13.org/~dpavlin/docman.html
43    
44          added more checking on entered filename (when creating file/dir)          It's relased under GPL by
45          added rename option          Dobrica Pavlinusic <dpavlin@rot13.org>
46    
47    
48  IMPORTANT INSTALLATION NOTE:  IMPORTANT INSTALLATION NOTE:
# Line 59  IMPORTANT INSTALLATION NOTE: Line 51  IMPORTANT INSTALLATION NOTE:
51          deleted files!          deleted files!
52    
53          .htusers is in form:          .htusers is in form:
54          login:Real Name:md5(loginpassword)          login:Real Name:[md5(loginpassword)|auth_*]:email@host.dom
55    
56    
57  TODO:  TODO:
58          mixed file/directory output (add type to each entry,          mixed file/directory output (add type to each entry,
59                  real support for links)                  real support for links)
60          retrieve old versions of files (overwritten)          access controll
61          show last lock date  
           
62  */  */
63    
64  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 80  TODO: Line 71  TODO:
71    
72  // GLOBAL PARAMETERS  // GLOBAL PARAMETERS
73  // =================  // =================
74  // Make modifications here to suit siteman to your needs  // Make modifications here to suit docman to your needs
75    
76  //      error_reporting(4) ;            // how verbose ?  //      error_reporting(4) ;            // how verbose ?
77    
78            // from where to include auth_*.php modules?
79            $gblIncDir = "/home/httpd/docman";
80    
81          // username/password should not be system          // username/password should not be system
82          // usernames/passwords !!          // usernames/passwords !!
83    
 //      $gblPw    = "hash_of_your_username_and_password" ;  
   
 //      $gblAuth  = false ;             // use builtin authentication  
         $gblAuth  = true ;             // use builtin authentication  
         $gblHash  = "md5" ;             // hash function to use  
   
84          $gblPw    = "";          $gblPw    = "";
85    
86          if ($gblAuth) {          // date format
                 $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";  
                 if (! file_exists($htusers_file)) {  
                         $htusers=fopen($htusers_file,"a+");  
                         fputs($htusers,"# Change owner of $htusers_file to root !!\n");  
                         fputs($htusers,"demo:full name:md5_hash\n");  
                         fclose($htusers);  
                 }  
                 $htusers=fopen($htusers_file,"r");  
                 while($user = fgetcsv($htusers,255,":")) {  
                         if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {  
                                 $gblUserName=$user[1];  
                                 $gblPw=$user[2];  
                                 $gblEmail=$user[3];  
                                 continue ;  
                         }  
                 }  
                 fclose($htusers);  
         }  
   
87  //      $gblDateFmt="D, F d, Y";  //      $gblDateFmt="D, F d, Y";
 //      $gblTimeFmt="g:i:sA";  
   
88          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
89    
90            // time format
91    //      $gblTimeFmt="g:i:sA";
92          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
93    
94          // Number of backup files to keep          // Number of backup files to keep
# Line 130  TODO: Line 100  TODO:
100          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
101          // WingDings font installed on your system          // WingDings font installed on your system
102    
103          $gblIcon = "GifIcon" ;          // MockIcon or GifIcon          $gblIcon="GifIcon";             // MockIcon or GifIcon
104    
105          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
106          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
107    
108          $gblIconLocation = "/icons/" ;          $gblIconLocation="/icons/";
109    
110          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
111          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 150  TODO: Line 120  TODO:
120          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",
121                                ".bmp",".xbm") ;                                ".bmp",".xbm") ;
122    
123            // Where are users? (by default in .htusers file)
124            $gblUsers = "htusers_file";
125    
126  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
127    
128  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
129    
130          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
131          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
132          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
133  ?>  ?>
# Line 233  A:HOVER { color:red; } Line 206  A:HOVER { color:red; }
206    
207  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
208                    
209          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
210          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
211    
212          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 252  function DetailPage($fsRoot,$relDir,$fn) Line 225  function DetailPage($fsRoot,$relDir,$fn)
225                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
226    
227          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
228          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
229                    $text .="delete a directory on this " ;
230            } else {
231                    $text .= "delete a single document on this " ;
232            };
233          $text .= "web site." ;            $text .= "web site." ;  
234          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
235          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 262  function DetailPage($fsRoot,$relDir,$fn) Line 239  function DetailPage($fsRoot,$relDir,$fn)
239                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
240                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
241                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
242                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
243                    $fgid=filegroup($fsPath);
244                    $userinfo = posix_getpwuid($fuid);
245                    $grpinfo = posix_getgrgid($fgid);
246                    echo "<PRE>";
247                    if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
248                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
249                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
250                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
251                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
252                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
253                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
254                  echo "</PRE>" ;                  echo "</PRE>" ;
255    
256          }          }
257    
258          if ( $editable && ($writable || !$exists) && !$file_lock ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
259                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
260                  rewind($fh) ;                  rewind($fh) ;
261                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 301  echo($fstr) ; ?></TEXTAREA> Line 283  echo($fstr) ; ?></TEXTAREA>
283          }          }
284          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
285                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
286                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
287                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
288                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
289  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
# Line 367  echo($fstr) ; ?></TEXTAREA> Line 349  echo($fstr) ; ?></TEXTAREA>
349  </FORM>  </FORM>
350    
351  <?php  <?php
352            
353          $name=basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
354          $logname=dirname("$fsDir/$fn")."/.log/$name";          $logname=dirname("$fsDir/$fn")."/.log/$name";
355          $bakdir=dirname("$fsDir/$fn")."/.bak";          $bakdir=dirname("$fsDir/$fn")."/.bak";
356          if (file_exists($logname)) {          if (file_exists($logname)) {
357                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
358                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
359                  $logarr = array();                  $logarr = array();
360                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
361                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
362                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
363                  }                  }
364                  fclose($log);                  fclose($log);
365                  print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";                  if (is_dir("$fsDir/$fn")) {
366                            $whatis="DIRECTORY";
367                    } else {
368                            $whatis="FILE";
369                    }
370                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
371                  $bakcount = 0;  // start from 0, skip fist backup (it's current)                  $bakcount = 0;  // start from 0, skip fist backup (it's current)
372                  while ($e = array_shift($logarr)) {                  while ($e = array_shift($logarr)) {
373                          if (strstr($e[4],"upload")) {                          if (strstr($e[4],"upload")) {
374                                  if (file_exists("$bakdir/$bakcount/$name")) {                                  if (file_exists("$bakdir/$bakcount/$name")) {
375                                          $e[4]="<a href=\"".dirname($relPath)."/.bak/$bakcount/$name\">$e[4]</a>";                                          $e[4]="<a href=\"$webRoot".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
376                                  }                                  }
377                                  $bakcount++;                                  $bakcount++;
378                          }                          }
# Line 646  function GifIcon($txt) { Line 633  function GifIcon($txt) {
633    
634  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
635    
636          global $gblEditable, $gblIcon, $gblModDays ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot ;
637    
638          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
639          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
640                  $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
641    
642          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
643    
# Line 714  function Navigate($fsRoot,$relDir) { Line 697  function Navigate($fsRoot,$relDir) {
697  <?php  <?php
698          }          }
699    
700    function plural($name,$count) {
701            $out="$count $name";
702            if ($count > 1) {
703                    $out.="s";
704            }
705            return $out;
706    }
707    
708          // output subdirs          // output subdirs
709          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
710                  sort($dirList) ;                  sort($dirList) ;
711  ?>  ?>
712    
713  <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>
714    
715  <?php  <?php
716                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
717    
718                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
719                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
720                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
721                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
722                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
723  ?>  ?>
724    
725  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
726  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
727    <?= $gblIcon("fldr") ?></A></TD>
728    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
729    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
730    
731  <?php  <?php
732                  }  // iterate over dirs                  }  // iterate over dirs
# Line 739  function Navigate($fsRoot,$relDir) { Line 735  function Navigate($fsRoot,$relDir) {
735    
736  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
737  </B></TD></TR>  </B></TD></TR>
738  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
739  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
740  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
741  <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>
# Line 829  function Navigate($fsRoot,$relDir) { Line 825  function Navigate($fsRoot,$relDir) {
825    
826  <?php  <?php
827            }  // iterate over files            }  // iterate over files
828          }  // end if no files          } else {  // end if no files
829    ?>
830     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
831      No files in this directory
832     </TD></TR>
833    <?
834            }
835    
836          if ($emptyDir) {          if ($emptyDir) {
837  ?>  ?>
# Line 849  function Navigate($fsRoot,$relDir) { Line 851  function Navigate($fsRoot,$relDir) {
851    
852  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
853    
 <TR><TD></TD><TD COLSPAN=5>  
854  <?  <?
855  if (file_exists(".info.inc")) {  if (file_exists(".info.inc")) {
856            print "<TR><TD></TD><TD COLSPAN=5>";
857          include(".info.inc");          include(".info.inc");
858            print "</TD></TR>
859            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
860  }  }
861  ?>  ?>
 </TD></TR>  
   
 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  
862    
863  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
864  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
# Line 866  if (file_exists(".info.inc")) { Line 867  if (file_exists(".info.inc")) {
867   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
868   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
869   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
870   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
871     </NOBR>
872   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE   <NOBR>OR <A HREF="<?= $self ?>?A=U&D=<?= urlencode($relDir) ?>">UPLOAD</A> A FILE
873   </NOBR>   </NOBR>
874  </TD></TR>  </TD></TR>
# Line 879  if (file_exists(".info.inc")) { Line 881  if (file_exists(".info.inc")) {
881    
882  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
883    
884  function UploadPage($fsRoot, $relDir, $filename) {  function UploadPage($fsRoot, $relDir, $filename="") {
885    
886          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
887          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 889  function UploadPage($fsRoot, $relDir, $f Line 891  function UploadPage($fsRoot, $relDir, $f
891  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
892   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
893  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
894  <? if (isset($filename)) { ?>  <? if (isset($filename) && $filename!="") { ?>
895  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
896  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
897  <? } ?>  <? } ?>
# Line 924  function Error($title,$text="") { Line 926  function Error($title,$text="") {
926    
927  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
928    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
929  function NoEntry() {  function NoEntry() {
930    
931          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 956  function NoEntry() { Line 935  function NoEntry() {
935          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
936          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
937          StartHTML($title,$text) ;          StartHTML($title,$text) ;
 ?>  
   
 <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">  
 <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">  
 <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>  
938    
 <?php  
939          EndHTML() ;          EndHTML() ;
940          exit ;          exit ;
941  }  }
942    
943  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
944    
945  function Logit($target,$msg) {  function LogIt($target,$msg) {
946    
947          $dir=dirname($target);          $dir=dirname($target);
948          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
# Line 996  function Logit($target,$msg) { Line 962  function Logit($target,$msg) {
962    
963  function WriteNote($target,$msg) {  function WriteNote($target,$msg) {
964    
965            $target=stripSlashes($target);
966          $dir=dirname($target);          $dir=dirname($target);
967          if (! file_exists($dir."/.note")) {          if (! file_exists($dir."/.note")) {
968                  mkdir($dir."/.note",0700);                  mkdir($dir."/.note",0700);
# Line 1012  function WriteNote($target,$msg) { Line 979  function WriteNote($target,$msg) {
979    
980  function ReadNote($target) {  function ReadNote($target) {
981    
982            $target=stripSlashes($target);
983          $dir=dirname($target);          $dir=dirname($target);
984          $file=basename($target);          $file=basename($target);
985          $msg="";          $msg="";
# Line 1020  function ReadNote($target) { Line 988  function ReadNote($target) {
988                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
989                  fclose($note);                  fclose($note);
990          }          }
991          return StripSlashes($msg);          return HtmlSpecialChars(StripSlashes($msg));
992    
993  }  }
994    
# Line 1028  function ReadNote($target) { Line 996  function ReadNote($target) {
996    
997  function MoveTo($source,$folder) {  function MoveTo($source,$folder) {
998    
999            $source=stripSlashes($source);
1000          $file=basename($source);          $file=basename($source);
1001          if (! file_exists($folder)) {          if (! file_exists($folder)) {
1002                  mkdir($folder,0700);                  mkdir($folder,0700);
# Line 1041  function MoveTo($source,$folder) { Line 1010  function MoveTo($source,$folder) {
1010    
1011  function Lock($target) {  function Lock($target) {
1012    
1013            $target=stripSlashes($target);
1014          $dir=dirname($target);          $dir=dirname($target);
1015          if (! file_exists($dir."/.lock")) {          if (! file_exists($dir."/.lock")) {
1016                  mkdir($dir."/.lock",0700);                  mkdir($dir."/.lock",0700);
# Line 1061  function Lock($target) { Line 1031  function Lock($target) {
1031    
1032  function CheckLock($target) {  function CheckLock($target) {
1033    
1034            $target=stripSlashes($target);
1035          $dir=dirname($target);          $dir=dirname($target);
1036          $file=basename($target);          $file=basename($target);
1037          $msg=0;          $msg=0;
# Line 1075  function CheckLock($target) { Line 1046  function CheckLock($target) {
1046    
1047  function Unlock($target) {  function Unlock($target) {
1048    
1049            $target=stripSlashes($target);
1050          $dir=dirname($target);          $dir=dirname($target);
1051          $file=basename($target);          $file=basename($target);
1052          if (file_exists($dir."/.lock/$file")) {          if (file_exists($dir."/.lock/$file")) {
# Line 1097  function urlpath($url) { Line 1069  function urlpath($url) {
1069    
1070  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1071    
1072  function safe_rename($from,$to) {  function safe_rename($fromdir,$fromfile,$tofile) {
1073          if (file_exists($from) && is_writable(dirname($to))) {          function try_rename($from,$to) {
1074                  rename($from,$to);  #               print "$from -> $to\n";
1075                    if (file_exists($from) && is_writeable(dirname($to))) {
1076                            rename($from,$to);
1077                    }
1078            }
1079    
1080            function try_dir($todir) {
1081                    if (! file_exists($todir)) {
1082                            mkdir($todir,0700);
1083                    }
1084            }
1085    
1086            $to="$fromdir/$tofile";
1087            $todir=dirname($to);
1088            $tofile=basename($to);
1089    
1090    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1091    
1092            try_rename("$fromdir/$fromfile","$todir/$tofile");
1093            try_dir("$todir/.log");
1094            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1095            try_dir("$todir/.note");
1096            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1097            try_dir("$todir/.lock");
1098            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1099            try_dir("$todir/.bak");
1100            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1101                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1102          }          }
1103  }  }
1104    
1105    
1106  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1107    
1108  // recursivly delete directory  // recursivly delete directory
# Line 1141  function DisplayChangeLog($day) { Line 1141  function DisplayChangeLog($day) {
1141          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1142          $logarr = array();          $logarr = array();
1143          while($line = fgetcsv($log,255,"\t")) {          while($line = fgetcsv($log,255,"\t")) {
1144                  if ($day!=1 || $day==1 && ($line[0]-time() < 24*60)) {                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1145                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1146                  }                  }
1147          }          }
1148          fclose($log);          fclose($log);
1149          $cl1=" class=lst"; $cl2="";          $cl1=" class=LST"; $cl2="";
1150          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1151          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1152                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
# Line 1157  function DisplayChangeLog($day) { Line 1157  function DisplayChangeLog($day) {
1157                  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";                  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";
1158          }          }
1159          print "</table>";          print "</table>";
1160            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1161  }  }
1162    
1163  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 1176  function DisplayChangeLog($day) { Line 1177  function DisplayChangeLog($day) {
1177          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1178          // creation if password not yet set.          // creation if password not yet set.
1179          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1180          if ($HASH != "") {  
1181                  CreateHash($USER, $PW) ;          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1182                  exit ;          // i.e. /home/httpd/html/docman
1183    
1184            // read user-defined configuration
1185            if (file_exists("$fsScriptDir/.docman.conf")) {
1186                    include("$fsScriptDir/.docman.conf");
1187            }
1188    
1189            // where do we get users from?
1190            if (file_exists("$gblIncDir/$gblUsers.php")) {
1191                    include("$gblIncDir/$gblUsers.php");
1192            } else {
1193                    Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>");
1194          }          }
1195    
1196          // authentication if $gblAuth == true          // authentication failure
1197          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1198                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
1199                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1200                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1201                  NoEntry() ;                  NoEntry() ;
1202                  exit ;                  exit ;
# Line 1196  function DisplayChangeLog($day) { Line 1208  function DisplayChangeLog($day) {
1208                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1209          }                }      
1210    
1211            $relDir=stripSlashes($relDir);
1212    
1213          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1214          // default : website root = ""          // default : website root = ""
1215    
# Line 1207  function DisplayChangeLog($day) { Line 1221  function DisplayChangeLog($day) {
1221          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1222    
1223          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1224          // i.e. /siteman          // i.e. /docman
   
         $fsScriptDir  = dirname($SCRIPT_FILENAME) ;      
         // i.e. /home/httpd/html/siteman  
1225    
1226          $gblFsRoot = substr($fsScriptDir,0,          // start on server root
1227            strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1228            // or on script root
1229            $gblFsRoot = $fsScriptDir;
1230          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1231    
1232          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1233          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1234            
1235            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1236                    $webRoot  = "https://";
1237            } else {
1238                    $webRoot  = "http://";
1239            }
1240            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1241    
1242            $FN=stripSlashes($FN);
1243    
1244    
1245          switch ($POSTACTION) {          switch ($POSTACTION) {
1246          case "UPLOAD" :          case "UPLOAD" :
1247                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1227  function DisplayChangeLog($day) { Line 1250  function DisplayChangeLog($day) {
1250                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1251                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1252                  $source = $FN ;                  $source = $FN ;
1253                    if (! file_exists($source)) {
1254                            Error("You must select file with browse to upload it!");
1255                    }
1256                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1257                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/$FN_name" ;
1258                  } else {                  } else {
# Line 1259  function DisplayChangeLog($day) { Line 1285  function DisplayChangeLog($day) {
1285    
1286          case "SAVE" :          case "SAVE" :
1287                  $path = $gblFsRoot . $RELPATH ;                  $path = $gblFsRoot . $RELPATH ;
1288                    $path=stripSlashes($path);
1289                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1290                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1291                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 1266  function DisplayChangeLog($day) { Line 1293  function DisplayChangeLog($day) {
1293                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1294                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1295                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1296                    $FILEDATA=stripSlashes($FILEDATA);
1297                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1298                  fclose($fh) ;                  fclose($fh) ;
1299                  clearstatcache() ;                  clearstatcache() ;
# Line 1289  function DisplayChangeLog($day) { Line 1317  function DisplayChangeLog($day) {
1317  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1318  // better keep it here altogether  // better keep it here altogether
1319  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1320                          if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1321                                  Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1322                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1323                          if ($fh) {                          if ($fh) {
# Line 1361  function DisplayChangeLog($day) { Line 1389  function DisplayChangeLog($day) {
1389                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1390    
1391                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1392                  safe_rename("$fsDir/$FN","$fsDir/$NEWNAME");                  safe_rename($fsDir,$FN,$NEWNAME);
                 safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");  
                 safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");  
                 safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");  
                 for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {  
                         safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");  
                 }  
   
1393                  break ;                  break ;
1394    
1395          case "NOTE" :            case "NOTE" :  
# Line 1399  function DisplayChangeLog($day) { Line 1420  function DisplayChangeLog($day) {
1420          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1421          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1422          // default : display directory $D          // default : display directory $D
1423            
1424          switch ($A) {          switch ($A) {
1425          case "U" :          case "U" :
1426                  // upload to $relDir                  // upload to $relDir
1427                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1428                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1429                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1430                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1431                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1432                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1433                  EndHTML() ;                  EndHTML() ;
1434                  exit ;                  exit ;
1435          case "E" :          case "E" :
1436                    $F=stripSlashes($F);
1437                  // detail of $relDir/$F                  // detail of $relDir/$F
1438                  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) ;
1439                  exit ;                  exit ;
1440          case "C" :          case "C" :
1441                    $F=stripSlashes($F);
1442                  // listing of $relDir/$F                  // listing of $relDir/$F
1443                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1444                  exit ;                  exit ;
# Line 1423  function DisplayChangeLog($day) { Line 1446  function DisplayChangeLog($day) {
1446                  // checkout                  // checkout
1447                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1448                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1449                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: $webRoot".urlpath("$relDir/$F"));
1450                  exit;                  exit;
1451          case "Ci" :          case "Ci" :
1452                    $F=stripSlashes($F);
1453                  // upload && update to $relDir                  // upload && update to $relDir
1454                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1455                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1456                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1457                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1458                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1459                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1460                  EndHTML() ;                  EndHTML() ;
# Line 1439  function DisplayChangeLog($day) { Line 1463  function DisplayChangeLog($day) {
1463                  // view                  // view
1464                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1465                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1466                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: $webRoot".urlpath("$relDir/$F"));
1467                  exit;                  exit;
1468          case "Ch" :          case "Ch" :
1469                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.43

  ViewVC Help
Powered by ViewVC 1.1.26