/[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.22 by dpavlin, Wed Sep 13 09:59:16 2000 UTC revision 1.45 by dpavlin, Thu Jun 21 08:56:35 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            // which files to hide (separated by ,)
124            $gblHide = "";
125    
126            // Where are users? (by default in .htusers file)
127            $gblUsers = "htusers_file";
128    
129  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
130    
131  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
132    
133          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
134          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
135          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
136  ?>  ?>
# Line 233  A:HOVER { color:red; } Line 209  A:HOVER { color:red; }
209    
210  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
211                    
212          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
213          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
214    
215          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 252  function DetailPage($fsRoot,$relDir,$fn) Line 228  function DetailPage($fsRoot,$relDir,$fn)
228                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
229    
230          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
231          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
232                    $text .="delete a directory on this " ;
233            } else {
234                    $text .= "delete a single document on this " ;
235            };
236          $text .= "web site." ;            $text .= "web site." ;  
237          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
238          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 262  function DetailPage($fsRoot,$relDir,$fn) Line 242  function DetailPage($fsRoot,$relDir,$fn)
242                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
243                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
244                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
245                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
246                    $fgid=filegroup($fsPath);
247                    $userinfo = posix_getpwuid($fuid);
248                    $grpinfo = posix_getgrgid($fgid);
249                    echo "<PRE>";
250                    if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
251                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
252                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
253                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
254                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
255                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
256                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
257                  echo "</PRE>" ;                  echo "</PRE>" ;
258    
259          }          }
260    
261          if ( $editable && ($writable || !$exists) && !$file_lock ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
262                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
263                  rewind($fh) ;                  rewind($fh) ;
264                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 301  echo($fstr) ; ?></TEXTAREA> Line 286  echo($fstr) ; ?></TEXTAREA>
286          }          }
287          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
288                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
289                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
290                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
291                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
292  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
# Line 373  echo($fstr) ; ?></TEXTAREA> Line 358  echo($fstr) ; ?></TEXTAREA>
358          $bakdir=dirname("$fsDir/$fn")."/.bak";          $bakdir=dirname("$fsDir/$fn")."/.bak";
359          if (file_exists($logname)) {          if (file_exists($logname)) {
360                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
361                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
362                  $logarr = array();                  $logarr = array();
363                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
364                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
365                          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]));
366                  }                  }
367                  fclose($log);                  fclose($log);
368                  print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";                  if (is_dir("$fsDir/$fn")) {
369                            $whatis="DIRECTORY";
370                    } else {
371                            $whatis="FILE";
372                    }
373                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
374                  $bakcount = 0;  // start from 0, skip fist backup (it's current)                  $bakcount = 0;  // start from 0, skip fist backup (it's current)
375                  while ($e = array_shift($logarr)) {                  while ($e = array_shift($logarr)) {
376                          if (strstr($e[4],"upload")) {                          if (strstr($e[4],"upload")) {
377                                  if (file_exists("$bakdir/$bakcount/$name")) {                                  if (file_exists("$bakdir/$bakcount/$name")) {
378                                          $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>";
379                                  }                                  }
380                                  $bakcount++;                                  $bakcount++;
381                          }                          }
# Line 646  function GifIcon($txt) { Line 636  function GifIcon($txt) {
636    
637  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
638    
639          global $gblEditable, $gblIcon, $gblModDays ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ;
640    
641          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
642          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
643                  $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
644    
645          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
646    
647            $hide_items=",$gblHide,";
648    
649          // read directory contents          // read directory contents
650          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
651                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
652          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
653                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
654                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
655                          $dirList[] = $item ;                          $dirList[] = $item ;
656                  } else if ( is_file($fsDir . $item) ) {                  } else if ( is_file($fsDir . $item) ) {
# Line 681  function Navigate($fsRoot,$relDir) { Line 669  function Navigate($fsRoot,$relDir) {
669          // scan deleted files          // scan deleted files
670          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
671                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
672                          if ( substr($item,0,1) == "." ) continue ;                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
673                          $fileList[] = ".del/$item" ;                                      $fileList[] = ".del/$item" ;            
674                  }                  }
675                  closedir($dir) ;                  closedir($dir) ;
# Line 714  function Navigate($fsRoot,$relDir) { Line 702  function Navigate($fsRoot,$relDir) {
702  <?php  <?php
703          }          }
704    
705    function plural($name,$count) {
706            $out="$count $name";
707            if ($count > 1) {
708                    $out.="s";
709            }
710            return $out;
711    }
712    
713          // output subdirs          // output subdirs
714          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
715                  sort($dirList) ;                  sort($dirList) ;
716  ?>  ?>
717    
718  <TR><TD></TD><TD COLSPAN=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>
719    
720  <?php  <?php
721                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
722    
723                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
724                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
725                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
726                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
727                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
728  ?>  ?>
729    
730  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
731  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
732    <?= $gblIcon("fldr") ?></A></TD>
733    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
734    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
735    
736  <?php  <?php
737                  }  // iterate over dirs                  }  // iterate over dirs
# Line 739  function Navigate($fsRoot,$relDir) { Line 740  function Navigate($fsRoot,$relDir) {
740    
741  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
742  </B></TD></TR>  </B></TD></TR>
743  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
744  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
745  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
746  <TD CLASS=TOP>LAST UPDATE</TD><TD CLASS=TOP>FILE SIZE</TD></TR>  <TD CLASS=TOP>LAST UPDATE</TD><TD CLASS=TOP>FILE SIZE</TD></TR>
# Line 829  function Navigate($fsRoot,$relDir) { Line 830  function Navigate($fsRoot,$relDir) {
830    
831  <?php  <?php
832            }  // iterate over files            }  // iterate over files
833          }  // end if no files          } else {  // end if no files
834    ?>
835     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
836      No files in this directory
837     </TD></TR>
838    <?
839            }
840    
841          if ($emptyDir) {          if ($emptyDir) {
842  ?>  ?>
# Line 849  function Navigate($fsRoot,$relDir) { Line 856  function Navigate($fsRoot,$relDir) {
856    
857  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
858    
 <TR><TD></TD><TD COLSPAN=5>  
859  <?  <?
860  if (file_exists(".info.inc")) {  if (file_exists(".info.inc")) {
861            print "<TR><TD></TD><TD COLSPAN=5>";
862          include(".info.inc");          include(".info.inc");
863            print "</TD></TR>
864            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
865  }  }
866  ?>  ?>
 </TD></TR>  
   
 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  
867    
868  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
869  <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 872  if (file_exists(".info.inc")) {
872   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
873   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
874   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
875   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
876     </NOBR>
877   <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
878   </NOBR>   </NOBR>
879  </TD></TR>  </TD></TR>
# Line 879  if (file_exists(".info.inc")) { Line 886  if (file_exists(".info.inc")) {
886    
887  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
888    
889  function UploadPage($fsRoot, $relDir, $filename) {  function UploadPage($fsRoot, $relDir, $filename="") {
890    
891          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
892          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 889  function UploadPage($fsRoot, $relDir, $f Line 896  function UploadPage($fsRoot, $relDir, $f
896  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
897   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
898  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
899  <? if (isset($filename)) { ?>  <? if (isset($filename) && $filename!="") { ?>
900  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
901  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
902  <? } ?>  <? } ?>
# Line 924  function Error($title,$text="") { Line 931  function Error($title,$text="") {
931    
932  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
933    
 function CreateHash($user, $pw) {  
   
         global $gblHash ;  // hash function to use  
   
         if ($user == "" || $pw == "") {  
                 $text = "either no password or no username supplied" ;  
                 Error("Create Hash",$text) ;  
         }  
         $title = "(Create Hash)" ;  
         StartHTML($title) ;  
         echo "<P ALIGN=center>" ;  
         echo "<BLOCKQUOTE>Copy the value below and paste it " ;  
         echo "into the<BR>value for \$gblPw in the source of " ;  
         echo "this file<BR><BR><B>" . $gblHash($user.$pw) ;  
         echo "</B><BR><BR>Hash function: " . $gblHash ;  
         echo "</BLOCKQUOTE></P>" ;  
         EndHTML() ;  
         exit ;  
   
 } // end function CreateHash  
   
 //////////////////////////////////////////////////////////////////  
   
934  function NoEntry() {  function NoEntry() {
935    
936          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 956  function NoEntry() { Line 940  function NoEntry() {
940          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
941          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
942          StartHTML($title,$text) ;          StartHTML($title,$text) ;
 ?>  
   
 <FORM ACTION="<?= $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>  
943    
 <?php  
944          EndHTML() ;          EndHTML() ;
945          exit ;          exit ;
946  }  }
# Line 1022  function ReadNote($target) { Line 993  function ReadNote($target) {
993                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
994                  fclose($note);                  fclose($note);
995          }          }
996          return StripSlashes($msg);          return HtmlSpecialChars(StripSlashes($msg));
997    
998  }  }
999    
# Line 1103  function urlpath($url) { Line 1074  function urlpath($url) {
1074    
1075  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1076    
1077  function safe_rename($from,$to) {  function safe_rename($fromdir,$fromfile,$tofile) {
1078          if (file_exists($from) && is_writable(dirname($to))) {          function try_rename($from,$to) {
1079                  rename($from,$to);  #               print "$from -> $to\n";
1080                    if (file_exists($from) && is_writeable(dirname($to))) {
1081                            rename($from,$to);
1082                    }
1083            }
1084    
1085            function try_dir($todir) {
1086                    if (! file_exists($todir)) {
1087                            mkdir($todir,0700);
1088                    }
1089            }
1090    
1091            $to="$fromdir/$tofile";
1092            $todir=dirname($to);
1093            $tofile=basename($to);
1094    
1095    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1096    
1097            try_rename("$fromdir/$fromfile","$todir/$tofile");
1098            try_dir("$todir/.log");
1099            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1100            try_dir("$todir/.note");
1101            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1102            try_dir("$todir/.lock");
1103            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1104            try_dir("$todir/.bak");
1105            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1106                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1107          }          }
1108  }  }
1109    
1110    
1111  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1112    
1113  // recursivly delete directory  // recursivly delete directory
# Line 1147  function DisplayChangeLog($day) { Line 1146  function DisplayChangeLog($day) {
1146          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1147          $logarr = array();          $logarr = array();
1148          while($line = fgetcsv($log,255,"\t")) {          while($line = fgetcsv($log,255,"\t")) {
1149                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60))) {                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1150                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1151                  }                  }
1152          }          }
1153          fclose($log);          fclose($log);
1154          $cl1=" class=lst"; $cl2="";          $cl1=" class=LST"; $cl2="";
1155          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1156          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1157                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
# Line 1183  function DisplayChangeLog($day) { Line 1182  function DisplayChangeLog($day) {
1182          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1183          // creation if password not yet set.          // creation if password not yet set.
1184          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1185          if ($HASH != "") {  
1186                  CreateHash($USER, $PW) ;          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1187                  exit ;          // i.e. /home/httpd/html/docman
1188    
1189            // read user-defined configuration
1190            if (file_exists("$fsScriptDir/.docman.conf")) {
1191                    include("$fsScriptDir/.docman.conf");
1192            }
1193    
1194            // where do we get users from?
1195            if (file_exists("$gblIncDir/$gblUsers.php")) {
1196                    include("$gblIncDir/$gblUsers.php");
1197            } else {
1198                    Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>");
1199          }          }
1200    
1201          // authentication if $gblAuth == true          // authentication failure
1202          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1203                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
1204                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1205                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1206                  NoEntry() ;                  NoEntry() ;
1207                  exit ;                  exit ;
# Line 1203  function DisplayChangeLog($day) { Line 1213  function DisplayChangeLog($day) {
1213                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1214          }                }      
1215    
1216            $relDir=stripSlashes($relDir);
1217    
1218          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1219          // default : website root = ""          // default : website root = ""
1220    
# Line 1214  function DisplayChangeLog($day) { Line 1226  function DisplayChangeLog($day) {
1226          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1227    
1228          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1229          // i.e. /siteman          // i.e. /docman
   
         $fsScriptDir  = dirname($SCRIPT_FILENAME) ;      
         // i.e. /home/httpd/html/siteman  
1230    
1231          $gblFsRoot = substr($fsScriptDir,0,          // start on server root
1232            strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1233            // or on script root
1234            $gblFsRoot = $fsScriptDir;
1235          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1236    
1237          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1238          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1239    
1240            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1241                    $webRoot  = "https://";
1242            } else {
1243                    $webRoot  = "http://";
1244            }
1245            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1246    
1247          $FN=stripSlashes($FN);          $FN=stripSlashes($FN);
1248    
1249    
1250          switch ($POSTACTION) {          switch ($POSTACTION) {
1251          case "UPLOAD" :          case "UPLOAD" :
1252                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1236  function DisplayChangeLog($day) { Line 1255  function DisplayChangeLog($day) {
1255                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1256                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1257                  $source = $FN ;                  $source = $FN ;
1258                    if (! file_exists($source)) {
1259                            Error("You must select file with browse to upload it!");
1260                    }
1261                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1262                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/$FN_name" ;
1263                  } else {                  } else {
# Line 1300  function DisplayChangeLog($day) { Line 1322  function DisplayChangeLog($day) {
1322  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1323  // better keep it here altogether  // better keep it here altogether
1324  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1325                          if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1326                                  Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1327                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1328                          if ($fh) {                          if ($fh) {
# Line 1372  function DisplayChangeLog($day) { Line 1394  function DisplayChangeLog($day) {
1394                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1395    
1396                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1397                  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");  
                 }  
   
1398                  break ;                  break ;
1399    
1400          case "NOTE" :            case "NOTE" :  
# Line 1417  function DisplayChangeLog($day) { Line 1432  function DisplayChangeLog($day) {
1432                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1433                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1434                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1435                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1436                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1437                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1438                  EndHTML() ;                  EndHTML() ;
# Line 1425  function DisplayChangeLog($day) { Line 1440  function DisplayChangeLog($day) {
1440          case "E" :          case "E" :
1441                  $F=stripSlashes($F);                  $F=stripSlashes($F);
1442                  // detail of $relDir/$F                  // detail of $relDir/$F
1443                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F") || is_dir("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1444                  exit ;                  exit ;
1445          case "C" :          case "C" :
1446                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1436  function DisplayChangeLog($day) { Line 1451  function DisplayChangeLog($day) {
1451                  // checkout                  // checkout
1452                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1453                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1454                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: $webRoot".urlpath("$relDir/$F"));
1455                  exit;                  exit;
1456          case "Ci" :          case "Ci" :
1457                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1444  function DisplayChangeLog($day) { Line 1459  function DisplayChangeLog($day) {
1459                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1460                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1461                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1462                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1463                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1464                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1465                  EndHTML() ;                  EndHTML() ;
# Line 1453  function DisplayChangeLog($day) { Line 1468  function DisplayChangeLog($day) {
1468                  // view                  // view
1469                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1470                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1471                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: $webRoot".urlpath("$relDir/$F"));
1472                  exit;                  exit;
1473          case "Ch" :          case "Ch" :
1474                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.26