/[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.51 by dpavlin, Mon Dec 17 10:00:51 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>  <?php
178            global $PHP_AUTH_USER,$PHP_AUTH_PW;
179            $url = $PHP_SELF."?relogin=";
180            if (isset($gblPw) && $gblPw != "") {
181                    $url .= $gblPw;
182            } else {
183                    $url .= md5($PHP_AUTH_USER.$PHP_AUTH_PW);
184            }
185            if (isset($PHP_AUTH_USER) && $PHP_AUTH_USER != "" && ($PHP_AUTH_PW == "" || !isset($PHP_AUTH_PW))) {
186                    $url_title="login";
187            } else {
188                    $url_title="relogin";
189            }
190    ?>
191    <small> [<a href="<?= $url ?>"><?= $url_title ?></a>]</small>
192  </B>  </B>
193  <BR>ANYPORTAL(php) Site Manager  <BR><small>
194  <br><small>  Document Manager <?= $gblVersion ?>, based on ANYPORTAL(php) Site Manager
195    <br>
196  &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,  &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
197  &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>,
198  &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 234  A:HOVER { color:red; }
234    
235  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
236                    
237          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
238          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
239    
240          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 243  function DetailPage($fsRoot,$relDir,$fn) Line 253  function DetailPage($fsRoot,$relDir,$fn)
253                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
254    
255          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
256          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
257                    $text .="delete a directory on this " ;
258            } else {
259                    $text .= "delete a single document on this " ;
260            };
261          $text .= "web site." ;            $text .= "web site." ;  
262          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
263          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 253  function DetailPage($fsRoot,$relDir,$fn) Line 267  function DetailPage($fsRoot,$relDir,$fn)
267                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
268                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
269                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
270                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $fuid=fileowner($fsPath);
271                    $fgid=filegroup($fsPath);
272                    $userinfo = posix_getpwuid($fuid);
273                    $grpinfo = posix_getgrgid($fgid);
274                    echo "<PRE>";
275                    if (!is_dir($fsPath)) echo "    file size: " . $fsize . " Bytes<BR>" ;
276                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
277                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
278                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . " [$fuid]</B><BR>" ;
279                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . " [$fgid]</B><BR>" ;
280                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
281                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
282                  echo "</PRE>" ;                  echo "</PRE>" ;
283    
284          }          }
285    
286          if ( $editable && ($writable || !$exists) && !$file_lock ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
287                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
288                  rewind($fh) ;                  rewind($fh) ;
289                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 292  echo($fstr) ; ?></TEXTAREA> Line 311  echo($fstr) ; ?></TEXTAREA>
311          }          }
312          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
313                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
314                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
315                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
316                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
317  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
# Line 364  echo($fstr) ; ?></TEXTAREA> Line 383  echo($fstr) ; ?></TEXTAREA>
383          $bakdir=dirname("$fsDir/$fn")."/.bak";          $bakdir=dirname("$fsDir/$fn")."/.bak";
384          if (file_exists($logname)) {          if (file_exists($logname)) {
385                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
386                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
387                  $logarr = array();                  $logarr = array();
388                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,512,"\t")) {
389                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
390                          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]));
391                  }                  }
392                  fclose($log);                  fclose($log);
393                  print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";                  if (is_dir("$fsDir/$fn")) {
394                            $whatis="DIRECTORY";
395                    } else {
396                            $whatis="FILE";
397                    }
398                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
399                  $bakcount = 0;  // start from 0, skip fist backup (it's current)                  $bakcount = 0;  // start from 0, skip fist backup (it's current)
400                  while ($e = array_shift($logarr)) {                  while ($e = array_shift($logarr)) {
401                          if (strstr($e[4],"upload")) {                          if (strstr($e[4],"upload")) {
402                                  if (file_exists("$bakdir/$bakcount/$name")) {                                  if (file_exists("$bakdir/$bakcount/$name")) {
403                                          $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>";
404                                  }                                  }
405                                  $bakcount++;                                  $bakcount++;
406                          }                          }
# Line 637  function GifIcon($txt) { Line 661  function GifIcon($txt) {
661    
662  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
663    
664          global $gblEditable, $gblIcon, $gblModDays ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ;
665    
666          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
667          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
668                  $webRoot  = "https://" . $GLOBALS["HTTP_HOST"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["HTTP_HOST"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
669    
670          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
671    
672            $hide_items=",$gblHide,";
673    
674          // read directory contents          // read directory contents
675          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
676                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
677          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
678                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
679                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
680                          $dirList[] = $item ;                          $dirList[] = $item ;
681                  } else if ( is_file($fsDir . $item) ) {                  } else if ( is_file($fsDir . $item) ) {
# Line 672  function Navigate($fsRoot,$relDir) { Line 694  function Navigate($fsRoot,$relDir) {
694          // scan deleted files          // scan deleted files
695          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
696                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
697                          if ( substr($item,0,1) == "." ) continue ;                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
698                          $fileList[] = ".del/$item" ;                                      $fileList[] = ".del/$item" ;            
699                  }                  }
700                  closedir($dir) ;                  closedir($dir) ;
# Line 693  function Navigate($fsRoot,$relDir) { Line 715  function Navigate($fsRoot,$relDir) {
715                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
716    
717          // updir bar              // updir bar    
718          if ($fsDir != $fsRoot) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
719                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
720                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
721  ?>  ?>
# Line 705  function Navigate($fsRoot,$relDir) { Line 727  function Navigate($fsRoot,$relDir) {
727  <?php  <?php
728          }          }
729    
730    function plural($name,$count) {
731            $out="$count $name";
732            if ($count > 1) {
733                    $out.="s";
734            }
735            return $out;
736    }
737    
738          // output subdirs          // output subdirs
739          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
740                  sort($dirList) ;                  sort($dirList) ;
741  ?>  ?>
742    
743  <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>
744    
745  <?php  <?php
746                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
747    
748                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
749                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
750                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
751                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
752                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
753  ?>  ?>
754    
755  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
756  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
757    <?= $gblIcon("fldr") ?></A></TD>
758    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
759    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
760    
761  <?php  <?php
762                  }  // iterate over dirs                  }  // iterate over dirs
# Line 730  function Navigate($fsRoot,$relDir) { Line 765  function Navigate($fsRoot,$relDir) {
765    
766  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
767  </B></TD></TR>  </B></TD></TR>
768  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
769  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
770  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
771  <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 863  function Navigate($fsRoot,$relDir) {
863  <?  <?
864          }          }
865    
866          if ($emptyDir) {          if ($emptyDir && $relDir != "") {
867  ?>  ?>
868    
869  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 862  if (file_exists(".info.inc")) { Line 897  if (file_exists(".info.inc")) {
897   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>   <NOBR>NAME <INPUT TYPE="TEXT" NAME="FN" SIZE=14>
898   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">   <INPUT TYPE="HIDDEN" NAME="POSTACTION" VALUE="CREATE">
899   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">   <INPUT TYPE="HIDDEN" NAME="DIR" VALUE="<?= $relDir ?>">
900   <INPUT TYPE="SUBMIT" VALUE="CREATE"></NOBR>   <INPUT TYPE="SUBMIT" VALUE="CREATE" NAME="CREATE">
901     </NOBR>
902   <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
903   </NOBR>   </NOBR>
904  </TD></TR>  </TD></TR>
# Line 875  if (file_exists(".info.inc")) { Line 911  if (file_exists(".info.inc")) {
911    
912  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
913    
914  function UploadPage($fsRoot, $relDir, $filename) {  function UploadPage($fsRoot, $relDir, $filename="") {
915    
916          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
917          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 885  function UploadPage($fsRoot, $relDir, $f Line 921  function UploadPage($fsRoot, $relDir, $f
921  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
922   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
923  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
924  <? if (isset($filename)) { ?>  <? if (isset($filename) && $filename!="") { ?>
925  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
926  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
927  <? } ?>  <? } ?>
# Line 920  function Error($title,$text="") { Line 956  function Error($title,$text="") {
956    
957  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
958    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
959  function NoEntry() {  function NoEntry() {
960    
961          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 951  function NoEntry() { Line 964  function NoEntry() {
964    
965          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
966          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
         StartHTML($title,$text) ;  
 ?>  
967    
968  <FORM ACTION="<?= $self ?>?HASH=create" METHOD="POST">          global $PHP_AUTH_USER,$PHP_AUTH_PW,$gblPw,$relogin;
969  <INPUT TYPE="HIDDEN" NAME="USER" VALUE="<?= $user ?>">          StartHTML($title,$text) ;
 <INPUT TYPE="HIDDEN" NAME="PW" VALUE="<?= $pw ?>">  
   
 <BLOCKQUOTE><B>If you are a site administrator:</B><BR><BR>  
 Click below to <B>generate a password hash</B><BR>from  
 the username-password pair you just<BR>entered. Then include the hash in  
 the source<BR>of this file.<BR><BR>  
 <INPUT TYPE="SUBMIT" VALUE="CREATE HASH">  
 </BLOCKQUOTE></FORM>  
970    
 <?php  
971          EndHTML() ;          EndHTML() ;
972          exit ;          exit ;
973  }  }
# Line 1018  function ReadNote($target) { Line 1020  function ReadNote($target) {
1020                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
1021                  fclose($note);                  fclose($note);
1022          }          }
1023          return StripSlashes($msg);          return HtmlSpecialChars(StripSlashes($msg));
1024    
1025  }  }
1026    
# Line 1099  function urlpath($url) { Line 1101  function urlpath($url) {
1101    
1102  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1103    
1104  function safe_rename($from,$to) {  function safe_rename($fromdir,$fromfile,$tofile) {
1105          if (file_exists($from) && is_writable(dirname($to))) {          function try_rename($from,$to) {
1106                  rename($from,$to);  #               print "$from -> $to\n";
1107                    if (file_exists($from) && is_writeable(dirname($to))) {
1108                            rename($from,$to);
1109                    }
1110            }
1111    
1112            function try_dir($todir) {
1113                    if (! file_exists($todir)) {
1114                            mkdir($todir,0700);
1115                    }
1116            }
1117    
1118            $to="$fromdir/$tofile";
1119            $todir=dirname($to);
1120            $tofile=basename($to);
1121    
1122    #       print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1123    
1124            try_rename("$fromdir/$fromfile","$todir/$tofile");
1125            try_dir("$todir/.log");
1126            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1127            try_dir("$todir/.note");
1128            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1129            try_dir("$todir/.lock");
1130            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1131            try_dir("$todir/.bak");
1132            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1133                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1134          }          }
1135  }  }
1136    
1137    
1138  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1139    
1140  // recursivly delete directory  // recursivly delete directory
# Line 1131  function ChangeLog($target,$msg) { Line 1161  function ChangeLog($target,$msg) {
1161          $log=fopen("$gblFsRoot/.changelog","a+");          $log=fopen("$gblFsRoot/.changelog","a+");
1162          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1163                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1164            $msg=str_replace("\t"," ",$msg);
1165          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1166          fclose($log);          fclose($log);
1167    
# Line 1142  function DisplayChangeLog($day) { Line 1173  function DisplayChangeLog($day) {
1173          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1174          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1175          $logarr = array();          $logarr = array();
1176          while($line = fgetcsv($log,255,"\t")) {          while($line = fgetcsv($log,512,"\t")) {
1177                    $line[0] .= sizeof($line);
1178                    while (sizeof($line) > 4) {
1179                            $tmp = array_pop($line);
1180                            $line.=" $tmp";
1181                    }
1182                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1183                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1184                  }                  }
1185          }          }
1186          fclose($log);          fclose($log);
1187          $cl1=" class=lst"; $cl2="";          $cl1=" class=LST"; $cl2="";
1188          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1189          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1190                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
# Line 1164  function DisplayChangeLog($day) { Line 1200  function DisplayChangeLog($day) {
1200    
1201  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1202    
1203    function Download($path) {
1204            global $HTTP_USER_AGENT;
1205            $file=basename($path);
1206            $size = filesize($path);
1207            //header("Content-Type: application/octet-stream");
1208            header("Content-Type: application/force-download");
1209            header("Content-Length: $size");
1210            // IE5.5 just downloads index.php if we don't do this
1211            if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {
1212                    header("Content-Disposition: filename=$file");
1213            } else {
1214                    header("Content-Disposition: attachment; filename=$file");
1215            }
1216            header("Content-Transfer-Encoding: binary");
1217            $fh = fopen($path, "r");
1218            fpassthru($fh);
1219    }
1220    
1221    
1222    //////////////////////////////////////////////////////////////////
1223    
1224    function chopsl($path) {
1225            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1226            $path=str_replace("//","/",$path);
1227            return $path;
1228    }
1229    
1230    //////////////////////////////////////////////////////////////////
1231  // MAIN PROGRAM  // MAIN PROGRAM
1232  // ============  // ============
1233  // query parameters: capital letters  // query parameters: capital letters
# Line 1179  function DisplayChangeLog($day) { Line 1243  function DisplayChangeLog($day) {
1243          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1244          // creation if password not yet set.          // creation if password not yet set.
1245          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1246          if ($HASH != "") {  
1247                  CreateHash($USER, $PW) ;          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1248                  exit ;          // i.e. /home/httpd/html/docman
1249    
1250            // read user-defined configuration
1251            if (file_exists("$fsScriptDir/.docman.conf")) {
1252                    include("$fsScriptDir/.docman.conf");
1253            }
1254    
1255            // where do we get users from?
1256            if (file_exists("$gblIncDir/$gblUsers.php")) {
1257                    include("$gblIncDir/$gblUsers.php");
1258            } else {
1259                    Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>");
1260            }
1261    
1262            // if no password, or empty password logout
1263            if (
1264                    isset($PHP_AUTH_USER) && (
1265                            !isset($relogin) || (
1266                                    isset($relogin) && $relogin != md5($PHP_AUTH_USER.$PHP_AUTH_PW)
1267                            )
1268                    ) && (
1269                            $PHP_AUTH_PW == "" || !isset($PHP_AUTH_PW)
1270                    )
1271               ) {
1272                    StartHTML("Logout completed","Your login credentials has been erased") ;
1273                    EndHTML() ;
1274                    exit ;
1275          }          }
1276    
1277          // authentication if $gblAuth == true          // authentication failure
1278          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1279                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin) {
1280                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1281                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1282                  NoEntry() ;                  NoEntry() ;
# Line 1199  function DisplayChangeLog($day) { Line 1289  function DisplayChangeLog($day) {
1289                  $relDir = urldecode($D) ;  // then use GET                  $relDir = urldecode($D) ;  // then use GET
1290          }                }      
1291    
1292            $relDir=stripSlashes($relDir);
1293    
1294          if ($relDir == "/") $relDir = "" ;                if ($relDir == "/") $relDir = "" ;      
1295          // default : website root = ""          // default : website root = ""
1296    
# Line 1212  function DisplayChangeLog($day) { Line 1304  function DisplayChangeLog($day) {
1304          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1305          // i.e. /docman          // i.e. /docman
1306    
         $fsScriptDir  = dirname($SCRIPT_FILENAME) ;      
         // i.e. /home/httpd/html/docman  
   
1307          // start on server root          // start on server root
1308  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1309          // or on script root          // or on script root
# Line 1224  function DisplayChangeLog($day) { Line 1313  function DisplayChangeLog($day) {
1313          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1314          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1315    
1316            if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
1317                    $webRoot  = "https://";
1318            } else {
1319                    $webRoot  = "http://";
1320            }
1321            $webRoot .= $GLOBALS["HTTP_HOST"] . $relScriptDir;
1322    
1323          $FN=stripSlashes($FN);          $FN=stripSlashes($FN);
1324    
1325    
1326          switch ($POSTACTION) {          switch ($POSTACTION) {
1327          case "UPLOAD" :          case "UPLOAD" :
1328                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1234  function DisplayChangeLog($day) { Line 1331  function DisplayChangeLog($day) {
1331                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1332                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1333                  $source = $FN ;                  $source = $FN ;
1334                    if (! file_exists($source)) {
1335                            Error("You must select file with browse to upload it!");
1336                    }
1337                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1338                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/$FN_name" ;
1339                  } else {                  } else {
# Line 1298  function DisplayChangeLog($day) { Line 1398  function DisplayChangeLog($day) {
1398  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1399  // better keep it here altogether  // better keep it here altogether
1400  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1401                          if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1402                                  Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1403                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1404                          if ($fh) {                          if ($fh) {
# Line 1370  function DisplayChangeLog($day) { Line 1470  function DisplayChangeLog($day) {
1470                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1471    
1472                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1473                  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");  
                 }  
   
1474                  break ;                  break ;
1475    
1476          case "NOTE" :            case "NOTE" :  
# Line 1407  function DisplayChangeLog($day) { Line 1500  function DisplayChangeLog($day) {
1500          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1501          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1502          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1503            // $A=I : include file .$F.php from $gblFsRoot
1504          // default : display directory $D          // default : display directory $D
1505    
1506          switch ($A) {          switch ($A) {
# Line 1423  function DisplayChangeLog($day) { Line 1517  function DisplayChangeLog($day) {
1517          case "E" :          case "E" :
1518                  $F=stripSlashes($F);                  $F=stripSlashes($F);
1519                  // detail of $relDir/$F                  // detail of $relDir/$F
1520                  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) ;
1521                  exit ;                  exit ;
1522          case "C" :          case "C" :
1523                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1433  function DisplayChangeLog($day) { Line 1527  function DisplayChangeLog($day) {
1527          case "Co" :          case "Co" :
1528                  // checkout                  // checkout
1529                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1530                  header("Content-Disposition: attachment; filename=$F" );                  Download("$gblFsRoot/$relDir/$F");
                 Header("Location: ".urlpath("$relDir/$F"));  
1531                  exit;                  exit;
1532          case "Ci" :          case "Ci" :
1533                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1450  function DisplayChangeLog($day) { Line 1543  function DisplayChangeLog($day) {
1543          case "V" :          case "V" :
1544                  // view                  // view
1545                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1546                  header("Content-Disposition: attachment; filename=$F" );                  if ($gblForceDownload) {
1547                  Header("Location: ".urlpath("$relDir/$F"));                          Download("$gblFsRoot/$relDir/$F");
1548                    } else {
1549                            header("Content-Disposition: attachment; filename=$F" );
1550                            Header("Location: $webRoot".urlpath("$relDir/$F"));
1551                    }
1552                  exit;                  exit;
1553          case "Ch" :          case "Ch" :
1554                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");
# Line 1463  function DisplayChangeLog($day) { Line 1560  function DisplayChangeLog($day) {
1560                  DisplayChangeLog(1);                  DisplayChangeLog(1);
1561                  EndHTML() ;                  EndHTML() ;
1562                  exit;                  exit;
1563            case "I" :
1564                    $F=stripSlashes($F);
1565                    $inc_file="${gblFsRoot}/.${F}.php";
1566                    if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include
1567                    if (!is_readable($inc_file))
1568                            Error("Read access to include file denied",".${F}.php");
1569                    $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
1570                    $title = "You should define \$title variable with page title";
1571                    include($inc_file);
1572                    StartHTML($title, $text) ;
1573                    print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1574                    EndHTML() ;
1575                    exit ;
1576          }          }
1577    
1578          // default: display directory $relDir          // default: display directory $relDir

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

  ViewVC Help
Powered by ViewVC 1.1.26