/[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.25 by dpavlin, Thu Dec 21 07:30:04 2000 UTC revision 1.47 by dpavlin, Wed Oct 31 08:23:35 2001 UTC
# Line 51  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:
# Line 75  TODO: Line 75  TODO:
75    
76  //      error_reporting(4) ;            // how verbose ?  //      error_reporting(4) ;            // how verbose ?
77    
78          // username/password should not be system          // from where to include auth_*.php modules?
79          // usernames/passwords !!          $gblIncDir = "/home/httpd/docman";
80    
81  //      $gblPw    = "hash_of_your_username_and_password" ;          // do we want to force download? (default is 0 for backward
82            // compatibility, but it's defined as 1 in docman.conf for all
83            // future applications!
84            $gblForceDownload = 0;
85    
86  //      $gblAuth  = false ;             // use builtin authentication          // username/password should not be system
87          $gblAuth  = true ;             // use builtin authentication          // usernames/passwords !!
         $gblHash  = "md5" ;             // hash function to use  
88    
89          $gblPw    = "";          $gblPw    = "";
90    
91          if ($gblAuth) {          // date format
                 $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";  
                 if (! file_exists($htusers_file)) {  
                         $htusers=fopen($htusers_file,"a+");  
                         fputs($htusers,"# Change owner of $htusers_file to root !!\n");  
                         fputs($htusers,"demo:full name:md5_hash\n");  
                         fclose($htusers);  
                 }  
                 $htusers=fopen($htusers_file,"r");  
                 while($user = fgetcsv($htusers,255,":")) {  
                         if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {  
                                 $gblUserName=$user[1];  
                                 $gblPw=$user[2];  
                                 $gblEmail=$user[3];  
                                 continue ;  
                         }  
                 }  
                 fclose($htusers);  
         }  
   
92  //      $gblDateFmt="D, F d, Y";  //      $gblDateFmt="D, F d, Y";
 //      $gblTimeFmt="g:i:sA";  
   
93          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
94    
95            // time format
96    //      $gblTimeFmt="g:i:sA";
97          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
98    
99          // Number of backup files to keep          // Number of backup files to keep
# Line 121  TODO: Line 105  TODO:
105          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
106          // WingDings font installed on your system          // WingDings font installed on your system
107    
108          $gblIcon = "GifIcon" ;          // MockIcon or GifIcon          $gblIcon="GifIcon";             // MockIcon or GifIcon
109    
110          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
111          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
112    
113          $gblIconLocation = "/icons/" ;          $gblIconLocation="/icons/";
114    
115          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
116          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 141  TODO: Line 125  TODO:
125          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",          $gblImages   = array( ".jpg",".jpeg",".gif",".png",".ico",
126                                ".bmp",".xbm") ;                                ".bmp",".xbm") ;
127    
128            // which files to hide (separated by ,)
129            $gblHide = "";
130    
131            // Where are users? (by default in .htusers file)
132            $gblUsers = "htusers_file";
133    
134  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
135    
136            $gblVersion = "1.8-dev";
137    
138  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
139    
140          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
141          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
142          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
143  ?>  ?>
# Line 153  function StartHTML($title,$text="") { Line 145  function StartHTML($title,$text="") {
145  <HTML>  <HTML>
146  <HEAD>  <HEAD>
147   <TITLE><?= $host . " " . $title ?></TITLE>   <TITLE><?= $host . " " . $title ?></TITLE>
148   <META NAME="description" CONTENT="PHP port of AnyPortal Site Manager">   <META NAME="description" CONTENT="Document Manager">
149   <META NAME="keywords" CONTENT="site manager, web site maintenance">   <META NAME="keywords" CONTENT="site manager, web site maintenance">
150   <META NAME="robots" CONTENT="noindex">   <META NAME="robots" CONTENT="noindex">
151   <META HTTP-EQUIV="expires" CONTENT="0">   <META HTTP-EQUIV="expires" CONTENT="0">
# Line 172  function StartHTML($title,$text="") { Line 164  function StartHTML($title,$text="") {
164  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
165    
166  function EndHTML() {  function EndHTML() {
167    
168    global $gblDateFmt, $gblTimeFmt, $gblUserName, $PHP_SELF, $gblPw, $gblVersion;
169    
170  ?>  ?>
171    
172  <HR>  <HR>
173  <P CLASS=FTR>  <P CLASS=FTR>
174  <B><?= date($GLOBALS[gblDateFmt]) ?> -  <B><?= date($gblDateFmt) ?> -
175  <?= date($GLOBALS[gblTimeFmt]) ?> -  <?= date($gblTimeFmt) ?> -
176  <?= $GLOBALS[gblUserName] ?>  <?= $gblUserName ?>
177  <small> [<a href="<?= $GLOBALS["PHP_SELF"] ?>?relogin=<?= $GLOBALS[gblPw] ?>">logout</a>]</small>  <small> [<a href="<?= $PHP_SELF ?>?relogin=<?= $gblPw ?>">logout</a>]</small>
178  </B>  </B>
179  <BR>ANYPORTAL(php) Site Manager  <BR><small>
180  <br><small>  Document Manager <?= $gblVersion ?>, based on ANYPORTAL(php) Site Manager
181    <br>
182  &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,  &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
183  &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,  &copy; 2000 by <A HREF="http://da.nger.org">d@nger.org</A>,
184  &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>  &copy; 2000 by <A HREF="http://www.rot13.org/~dpavlin/">DbP</A>
# Line 224  A:HOVER { color:red; } Line 220  A:HOVER { color:red; }
220    
221  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
222                    
223          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
224          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
225    
226          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 243  function DetailPage($fsRoot,$relDir,$fn) Line 239  function DetailPage($fsRoot,$relDir,$fn)
239                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
240    
241          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
242          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
243                    $text .="delete a directory on this " ;
244            } else {
245                    $text .= "delete a single document on this " ;
246            };
247          $text .= "web site." ;            $text .= "web site." ;  
248          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
249          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 253  function DetailPage($fsRoot,$relDir,$fn) Line 253  function DetailPage($fsRoot,$relDir,$fn)
253                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
254                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
255                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
256                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
257                    $fgid=filegroup($fsPath);
258                    $userinfo = posix_getpwuid($fuid);
259                    $grpinfo = posix_getgrgid($fgid);
260                    echo "<PRE>";
261                    if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
262                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
263                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
264                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
265                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
266                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
267                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
268                  echo "</PRE>" ;                  echo "</PRE>" ;
269    
270          }          }
271    
272          if ( $editable && ($writable || !$exists) && !$file_lock ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
273                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
274                  rewind($fh) ;                  rewind($fh) ;
275                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 292  echo($fstr) ; ?></TEXTAREA> Line 297  echo($fstr) ; ?></TEXTAREA>
297          }          }
298          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
299                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
300                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
301                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
302                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
303  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
# Line 364  echo($fstr) ; ?></TEXTAREA> Line 369  echo($fstr) ; ?></TEXTAREA>
369          $bakdir=dirname("$fsDir/$fn")."/.bak";          $bakdir=dirname("$fsDir/$fn")."/.bak";
370          if (file_exists($logname)) {          if (file_exists($logname)) {
371                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
372                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
373                  $logarr = array();                  $logarr = array();
374                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
375                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
376                          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]));
377                  }                  }
378                  fclose($log);                  fclose($log);
379                  print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";                  if (is_dir("$fsDir/$fn")) {
380                            $whatis="DIRECTORY";
381                    } else {
382                            $whatis="FILE";
383                    }
384                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
385                  $bakcount = 0;  // start from 0, skip fist backup (it's current)                  $bakcount = 0;  // start from 0, skip fist backup (it's current)
386                  while ($e = array_shift($logarr)) {                  while ($e = array_shift($logarr)) {
387                          if (strstr($e[4],"upload")) {                          if (strstr($e[4],"upload")) {
388                                  if (file_exists("$bakdir/$bakcount/$name")) {                                  if (file_exists("$bakdir/$bakcount/$name")) {
389                                          $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>";
390                                  }                                  }
391                                  $bakcount++;                                  $bakcount++;
392                          }                          }
# Line 637  function GifIcon($txt) { Line 647  function GifIcon($txt) {
647    
648  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
649    
650          global $gblEditable, $gblIcon, $gblModDays ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ;
651    
652          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
653          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
654                  $webRoot  = "https://" . $GLOBALS["HTTP_HOST"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["HTTP_HOST"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
655    
656          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
657    
658            $hide_items=",$gblHide,";
659    
660          // read directory contents          // read directory contents
661          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
662                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
663          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
664                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
665                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
666                          $dirList[] = $item ;                          $dirList[] = $item ;
667                  } else if ( is_file($fsDir . $item) ) {                  } else if ( is_file($fsDir . $item) ) {
# Line 672  function Navigate($fsRoot,$relDir) { Line 680  function Navigate($fsRoot,$relDir) {
680          // scan deleted files          // scan deleted files
681          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
682                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
683                          if ( substr($item,0,1) == "." ) continue ;                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
684                          $fileList[] = ".del/$item" ;                                      $fileList[] = ".del/$item" ;            
685                  }                  }
686                  closedir($dir) ;                  closedir($dir) ;
# Line 705  function Navigate($fsRoot,$relDir) { Line 713  function Navigate($fsRoot,$relDir) {
713  <?php  <?php
714          }          }
715    
716    function plural($name,$count) {
717            $out="$count $name";
718            if ($count > 1) {
719                    $out.="s";
720            }
721            return $out;
722    }
723    
724          // output subdirs          // output subdirs
725          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
726                  sort($dirList) ;                  sort($dirList) ;
727  ?>  ?>
728    
729  <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>
730    
731  <?php  <?php
732                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
733    
734                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
735                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
736                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
737                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
738                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
739  ?>  ?>
740    
741  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
742  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
743    <?= $gblIcon("fldr") ?></A></TD>
744    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
745    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
746    
747  <?php  <?php
748                  }  // iterate over dirs                  }  // iterate over dirs
# Line 730  function Navigate($fsRoot,$relDir) { Line 751  function Navigate($fsRoot,$relDir) {
751    
752  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
753  </B></TD></TR>  </B></TD></TR>
754  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
755  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
756  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
757  <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 828  function Navigate($fsRoot,$relDir) { Line 849  function Navigate($fsRoot,$relDir) {
849  <?  <?
850          }          }
851    
852          if ($emptyDir) {          if ($emptyDir && $relDir != "") {
853  ?>  ?>
854    
855  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 862  if (file_exists(".info.inc")) { Line 883  if (file_exists(".info.inc")) {
883   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
884   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
885   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
886   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
887     </NOBR>
888   <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
889   </NOBR>   </NOBR>
890  </TD></TR>  </TD></TR>
# Line 875  if (file_exists(".info.inc")) { Line 897  if (file_exists(".info.inc")) {
897    
898  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
899    
900  function UploadPage($fsRoot, $relDir, $filename) {  function UploadPage($fsRoot, $relDir, $filename="") {
901    
902          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
903          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 885  function UploadPage($fsRoot, $relDir, $f Line 907  function UploadPage($fsRoot, $relDir, $f
907  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
908   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
909  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
910  <? if (isset($filename)) { ?>  <? if (isset($filename) && $filename!="") { ?>
911  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
912  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
913  <? } ?>  <? } ?>
# Line 920  function Error($title,$text="") { Line 942  function Error($title,$text="") {
942    
943  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
944    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
945  function NoEntry() {  function NoEntry() {
946    
947          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 952  function NoEntry() { Line 951  function NoEntry() {
951          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
952          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
953          StartHTML($title,$text) ;          StartHTML($title,$text) ;
 ?>  
954    
 <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>  
   
 <?php  
955          EndHTML() ;          EndHTML() ;
956          exit ;          exit ;
957  }  }
# Line 1018  function ReadNote($target) { Line 1004  function ReadNote($target) {
1004                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
1005                  fclose($note);                  fclose($note);
1006          }          }
1007          return StripSlashes($msg);          return HtmlSpecialChars(StripSlashes($msg));
1008    
1009  }  }
1010    
# Line 1099  function urlpath($url) { Line 1085  function urlpath($url) {
1085    
1086  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1087    
1088  function safe_rename($from,$to) {  function safe_rename($fromdir,$fromfile,$tofile) {
1089          if (file_exists($from) && is_writable(dirname($to))) {          function try_rename($from,$to) {
1090                  rename($from,$to);  #               print "$from -> $to\n";
1091                    if (file_exists($from) && is_writeable(dirname($to))) {
1092                            rename($from,$to);
1093                    }
1094            }
1095    
1096            function try_dir($todir) {
1097                    if (! file_exists($todir)) {
1098                            mkdir($todir,0700);
1099                    }
1100            }
1101    
1102            $to="$fromdir/$tofile";
1103            $todir=dirname($to);
1104            $tofile=basename($to);
1105    
1106    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1107    
1108            try_rename("$fromdir/$fromfile","$todir/$tofile");
1109            try_dir("$todir/.log");
1110            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1111            try_dir("$todir/.note");
1112            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1113            try_dir("$todir/.lock");
1114            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1115            try_dir("$todir/.bak");
1116            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1117                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1118          }          }
1119  }  }
1120    
1121    
1122  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1123    
1124  // recursivly delete directory  // recursivly delete directory
# Line 1148  function DisplayChangeLog($day) { Line 1162  function DisplayChangeLog($day) {
1162                  }                  }
1163          }          }
1164          fclose($log);          fclose($log);
1165          $cl1=" class=lst"; $cl2="";          $cl1=" class=LST"; $cl2="";
1166          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1167          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1168                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
# Line 1164  function DisplayChangeLog($day) { Line 1178  function DisplayChangeLog($day) {
1178    
1179  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1180    
1181    function Download($path) {
1182            global $HTTP_USER_AGENT;
1183            $file=basename($path);
1184            $size = filesize($path);
1185            //header("Content-Type: application/octet-stream");
1186            header("Content-Type: application/force-download");
1187            header("Content-Length: $size");
1188            // IE5.5 just downloads index.php if we don't do this
1189            if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {
1190                    header("Content-Disposition: filename=$file");
1191            } else {
1192                    header("Content-Disposition: attachment; filename=$file");
1193            }
1194            header("Content-Transfer-Encoding: binary");
1195            $fh = fopen($path, "r");
1196            fpassthru($fh);
1197    }
1198    
1199    
1200    //////////////////////////////////////////////////////////////////
1201    
1202  // MAIN PROGRAM  // MAIN PROGRAM
1203  // ============  // ============
1204  // query parameters: capital letters  // query parameters: capital letters
# Line 1179  function DisplayChangeLog($day) { Line 1214  function DisplayChangeLog($day) {
1214          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1215          // creation if password not yet set.          // creation if password not yet set.
1216          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1217          if ($HASH != "") {  
1218                  CreateHash($USER, $PW) ;          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1219                  exit ;          // i.e. /home/httpd/html/docman
1220    
1221            // read user-defined configuration
1222            if (file_exists("$fsScriptDir/.docman.conf")) {
1223                    include("$fsScriptDir/.docman.conf");
1224          }          }
1225    
1226          // authentication if $gblAuth == true          // where do we get users from?
1227          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if (file_exists("$gblIncDir/$gblUsers.php")) {
1228                    include("$gblIncDir/$gblUsers.php");
1229            } else {
1230                    Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>");
1231            }
1232    
1233            // authentication failure
1234            if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1235                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
1236                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1237                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
# Line 1199  function DisplayChangeLog($day) { Line 1245  function DisplayChangeLog($day) {
1245                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1246          }                }      
1247    
1248            $relDir=stripSlashes($relDir);
1249    
1250          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1251          // default : website root = ""          // default : website root = ""
1252    
# Line 1212  function DisplayChangeLog($day) { Line 1260  function DisplayChangeLog($day) {
1260          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1261          // i.e. /docman          // i.e. /docman
1262    
         $fsScriptDir  = dirname($SCRIPT_FILENAME) ;      
         // i.e. /home/httpd/html/docman  
   
1263          // start on server root          // start on server root
1264  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1265          // or on script root          // or on script root
# Line 1224  function DisplayChangeLog($day) { Line 1269  function DisplayChangeLog($day) {
1269          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1270          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1271    
1272            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1273                    $webRoot  = "https://";
1274            } else {
1275                    $webRoot  = "http://";
1276            }
1277            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1278    
1279          $FN=stripSlashes($FN);          $FN=stripSlashes($FN);
1280    
1281    
1282          switch ($POSTACTION) {          switch ($POSTACTION) {
1283          case "UPLOAD" :          case "UPLOAD" :
1284                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1234  function DisplayChangeLog($day) { Line 1287  function DisplayChangeLog($day) {
1287                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1288                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1289                  $source = $FN ;                  $source = $FN ;
1290                    if (! file_exists($source)) {
1291                            Error("You must select file with browse to upload it!");
1292                    }
1293                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1294                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/$FN_name" ;
1295                  } else {                  } else {
# Line 1298  function DisplayChangeLog($day) { Line 1354  function DisplayChangeLog($day) {
1354  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1355  // better keep it here altogether  // better keep it here altogether
1356  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1357                          if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1358                                  Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1359                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1360                          if ($fh) {                          if ($fh) {
# Line 1370  function DisplayChangeLog($day) { Line 1426  function DisplayChangeLog($day) {
1426                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1427    
1428                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1429                  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");  
                 }  
   
1430                  break ;                  break ;
1431    
1432          case "NOTE" :            case "NOTE" :  
# Line 1423  function DisplayChangeLog($day) { Line 1472  function DisplayChangeLog($day) {
1472          case "E" :          case "E" :
1473                  $F=stripSlashes($F);                  $F=stripSlashes($F);
1474                  // detail of $relDir/$F                  // detail of $relDir/$F
1475                  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) ;
1476                  exit ;                  exit ;
1477          case "C" :          case "C" :
1478                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1433  function DisplayChangeLog($day) { Line 1482  function DisplayChangeLog($day) {
1482          case "Co" :          case "Co" :
1483                  // checkout                  // checkout
1484                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1485                  header("Content-Disposition: attachment; filename=$F" );                  Download("$gblFsRoot/$relDir/$F");
                 Header("Location: ".urlpath("$relDir/$F"));  
1486                  exit;                  exit;
1487          case "Ci" :          case "Ci" :
1488                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1450  function DisplayChangeLog($day) { Line 1498  function DisplayChangeLog($day) {
1498          case "V" :          case "V" :
1499                  // view                  // view
1500                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1501                  header("Content-Disposition: attachment; filename=$F" );                  if ($gblForceDownload) {
1502                  Header("Location: ".urlpath("$relDir/$F"));                          Download("$gblFsRoot/$relDir/$F");
1503                    } else {
1504                            header("Content-Disposition: attachment; filename=$F" );
1505                            Header("Location: $webRoot".urlpath("$relDir/$F"));
1506                    }
1507                  exit;                  exit;
1508          case "Ch" :          case "Ch" :
1509                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.47

  ViewVC Help
Powered by ViewVC 1.1.26