/[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.21 by dpavlin, Wed Sep 13 08:27:43 2000 UTC revision 1.35 by dpavlin, Sun Mar 11 15:36:51 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 154  TODO: Line 124  TODO:
124    
125  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
126    
127          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
128          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
129          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
130  ?>  ?>
# Line 233  A:HOVER { color:red; } Line 203  A:HOVER { color:red; }
203    
204  function DetailPage($fsRoot,$relDir,$fn) {  function DetailPage($fsRoot,$relDir,$fn) {
205                    
206          global $gblEditable, $gblImages ;          global $gblEditable, $gblImages, $webRoot ;
207          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
208    
209          $relPath  = $relDir . "/" . $fn ;          $relPath  = $relDir . "/" . $fn ;
# Line 252  function DetailPage($fsRoot,$relDir,$fn) Line 222  function DetailPage($fsRoot,$relDir,$fn)
222                  Error("Creation denied",$relDir) ;                  Error("Creation denied",$relDir) ;
223    
224          $text  = "Use this page to view, modify or " ;          $text  = "Use this page to view, modify or " ;
225          $text .= "delete a single document on this " ;          if (is_dir($fsPath)) {
226                    $text .="delete a directory on this " ;
227            } else {
228                    $text .= "delete a single document on this " ;
229            };
230          $text .= "web site." ;            $text .= "web site." ;  
231          $title = "(Detail Page)" ;          $title = "(Detail Page)" ;
232          StartHTML($title, $text) ;          StartHTML($title, $text) ;
# Line 262  function DetailPage($fsRoot,$relDir,$fn) Line 236  function DetailPage($fsRoot,$relDir,$fn)
236                  $fsize = filesize($fsPath) ;                  $fsize = filesize($fsPath) ;
237                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;                  $fmodified = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", filemtime($fsPath)) ;
238                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;                  $faccessed = date("$GLOBALS[gblDateFmt] $GLOBALS[gblTimeFmt]", fileatime($fsPath)) ;
239                  echo "<PRE>    file size: " . $fsize . " Bytes<BR>" ;                  $userinfo = posix_getpwuid(fileowner($fsPath));
240                    $grpinfo = posix_getgrgid(filegroup($fsPath));
241                    echo "<PRE>";
242                    if (!is_dir($fsPath)) echo "file size: " . $fsize . " Bytes<BR>" ;
243                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;                  echo "last modified: <B>" . $fmodified . "</B><BR>" ;
244                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;                  echo "last accessed: <B>" . $faccessed . "</B><BR>" ;
245                  echo "        owner: <B>" . fileowner($fsPath) . "</B><BR>" ;                  echo "        owner: <B>" . $userinfo["name"] . "</B><BR>" ;
246                  echo "        group: <B>" . filegroup($fsPath) . "</B><BR>" ;                  echo "        group: <B>" . $grpinfo["name"] . "</B><BR>" ;
247                  echo "  permissions: <B>" ;                  echo "  permissions: <B>" ;
248                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;                  echo printf( "%o", fileperms($fsPath) ) . "</B>" ;
249                  echo "</PRE>" ;                  echo "</PRE>" ;
250    
251          }          }
252    
253          if ( $editable && ($writable || !$exists) && !$file_lock ) {          if ( !is_dir($fsPath) && $editable && ($writable || !$exists) && !$file_lock ) {
254                  $fh = fopen($fsPath,"a+") ;                  $fh = fopen($fsPath,"a+") ;
255                  rewind($fh) ;                  rewind($fh) ;
256                  $fstr = fread($fh,filesize($fsPath)) ;                  $fstr = fread($fh,filesize($fsPath)) ;
# Line 301  echo($fstr) ; ?></TEXTAREA> Line 278  echo($fstr) ; ?></TEXTAREA>
278          }          }
279          if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
280                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
281                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"$webRoot".urlpath($relPath)."\" BORDER=0 " ;
282                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
283                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;                  $tstr .= (int)(($fsize+1023)/1024) . "Kb\">" ;
284  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;  //              echo htmlentities($tstr) . "<BR><BR>" . $tstr ;
# Line 367  echo($fstr) ; ?></TEXTAREA> Line 344  echo($fstr) ; ?></TEXTAREA>
344  </FORM>  </FORM>
345    
346  <?php  <?php
347            
348          $name=basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
349          $logname=dirname("$fsDir/$fn")."/.log/$name";          $logname=dirname("$fsDir/$fn")."/.log/$name";
350          $bakdir=dirname("$fsDir/$fn")."/.bak";          $bakdir=dirname("$fsDir/$fn")."/.bak";
351          if (file_exists($logname)) {          if (file_exists($logname)) {
352                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
353                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
354                  $logarr = array();                  $logarr = array();
355                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
356                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
357                          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]));
358                  }                  }
359                  fclose($log);                  fclose($log);
360                  print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";                  if (is_dir("$fsDir/$fn")) {
361                            $whatis="DIRECTORY";
362                    } else {
363                            $whatis="FILE";
364                    }
365                    print "<hr><br><b>CHANGES TO THIS $whatis</b><br><table border=0 width=100%>\n";
366                  $bakcount = 0;  // start from 0, skip fist backup (it's current)                  $bakcount = 0;  // start from 0, skip fist backup (it's current)
367                  while ($e = array_shift($logarr)) {                  while ($e = array_shift($logarr)) {
368                          if (strstr($e[4],"upload")) {                          if (strstr($e[4],"upload")) {
369                                  if (file_exists("$bakdir/$bakcount/$name")) {                                  if (file_exists("$bakdir/$bakcount/$name")) {
370                                          $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>";
371                                  }                                  }
372                                  $bakcount++;                                  $bakcount++;
373                          }                          }
# Line 646  function GifIcon($txt) { Line 628  function GifIcon($txt) {
628    
629  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
630    
631          global $gblEditable, $gblIcon, $gblModDays ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot ;
632    
633          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
634          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {  
635                  $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;          $fsDir = $fsRoot . $relDir . "/" ; // current directory
         } else {  
                 $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;  
         }  
         $fsDir    = $fsRoot . $relDir . "/" ; // current directory  
636    
637          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
638    
# Line 719  function Navigate($fsRoot,$relDir) { Line 697  function Navigate($fsRoot,$relDir) {
697                  sort($dirList) ;                  sort($dirList) ;
698  ?>  ?>
699    
700  <TR><TD></TD><TD COLSPAN=5 CLASS=TOP><HR>DIRECTORY NAME</TD></TR>  <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>
701    
702  <?php  <?php
703                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
704    
705                            $info_url=$self."?A=E&F=".urlencode($dir)."&D=".urlencode($relDir);
706                          $tstr = "<A HREF=\"" . $self . "?D=" ;                          $tstr = "<A HREF=\"" . $self . "?D=" ;
707                          $tstr .= urlencode($relDir."/".$dir) ;                          $tstr .= urlencode($relDir."/".$dir) ;
708                          $tstr .= "\">" . $dir . "/</A>" ;                          $tstr .= "\">" . $dir . "/</A>" ;
709                            $note_html="<a href=\"$info_url#note\">".$gblIcon("note")."</a>".ReadNote($fsDir.$dir);
710  ?>  ?>
711    
712  <TR><TD><?= $gblIcon("fldr") ?></TD>  <TR><TD>
713  <TD COLSPAN=5 CLASS=LST><?= $tstr ?></TD></TR>  <A HREF="<?= $info_url ?>" TITLE="View/Edit">
714    <?= $gblIcon("fldr") ?></A></TD>
715    <TD COLSPAN=2 CLASS=LST><?= $tstr ?></TD>
716    <TD COLSPAN=3 CLASS=LST><?= $note_html ?></TD></TR>
717    
718  <?php  <?php
719                  }  // iterate over dirs                  }  // iterate over dirs
# Line 829  function Navigate($fsRoot,$relDir) { Line 812  function Navigate($fsRoot,$relDir) {
812    
813  <?php  <?php
814            }  // iterate over files            }  // iterate over files
815          }  // end if no files          } else {  // end if no files
816    ?>
817     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
818      No files in this directory
819     </TD></TR>
820    <?
821            }
822    
823          if ($emptyDir) {          if ($emptyDir) {
824  ?>  ?>
# Line 849  function Navigate($fsRoot,$relDir) { Line 838  function Navigate($fsRoot,$relDir) {
838    
839  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
840    
 <TR><TD></TD><TD COLSPAN=5>  
841  <?  <?
842  if (file_exists(".info.inc")) {  if (file_exists(".info.inc")) {
843            print "<TR><TD></TD><TD COLSPAN=5>";
844          include(".info.inc");          include(".info.inc");
845            print "</TD></TR>
846            <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
847  }  }
848  ?>  ?>
 </TD></TR>  
   
 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  
849    
850  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
851  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
# Line 879  if (file_exists(".info.inc")) { Line 867  if (file_exists(".info.inc")) {
867    
868  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
869    
870  function UploadPage($fsRoot, $relDir, $filename) {  function UploadPage($fsRoot, $relDir, $filename="") {
871    
872          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
873          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 889  function UploadPage($fsRoot, $relDir, $f Line 877  function UploadPage($fsRoot, $relDir, $f
877  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
878   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
879  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
880  <? if (isset($filename)) { ?>  <? if (isset($filename) && $filename!="") { ?>
881  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
882  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
883  <? } ?>  <? } ?>
# Line 924  function Error($title,$text="") { Line 912  function Error($title,$text="") {
912    
913  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
914    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
915  function NoEntry() {  function NoEntry() {
916    
917          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 956  function NoEntry() { Line 921  function NoEntry() {
921          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
922          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
923          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>  
924    
 <?php  
925          EndHTML() ;          EndHTML() ;
926          exit ;          exit ;
927  }  }
# Line 978  the source<BR>of this file.<BR><BR> Line 930  the source<BR>of this file.<BR><BR>
930    
931  function LogIt($target,$msg) {  function LogIt($target,$msg) {
932    
         $target=stripSlashes($target);  
933          $dir=dirname($target);          $dir=dirname($target);
934          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
935                  mkdir($dir."/.log",0700);                  mkdir($dir."/.log",0700);
# Line 1104  function urlpath($url) { Line 1055  function urlpath($url) {
1055    
1056  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1057    
1058  function safe_rename($from,$to) {  function safe_rename($fromdir,$fromfile,$tofile) {
1059          if (file_exists($from) && is_writable(dirname($to))) {          function try_rename($from,$to) {
1060                  rename($from,$to);                  print "$from -> $to\n";
1061                    if (file_exists($from) && is_writeable(dirname($to))) {
1062                            rename($from,$to);
1063                    }
1064            }
1065    
1066            function try_dir($todir) {
1067                    if (! file_exists($todir)) {
1068                            mkdir($todir,0700);
1069                    }
1070            }
1071    
1072            $to="$fromdir/$tofile";
1073            $todir=dirname($to);
1074            $tofile=basename($to);
1075    
1076            print "<pre>$fromdir / $fromfile -> $todir / $tofile\n\n";
1077    
1078            try_rename("$fromdir/$fromfile","$todir/$tofile");
1079            try_dir("$todir/.log");
1080            try_rename("$fromdir/.log/$fromfile","$todir/.log/$tofile");
1081            try_dir("$todir/.note");
1082            try_rename("$fromdir/.note/$fromfile","$todir/.note/$tofile");
1083            try_dir("$todir/.lock");
1084            try_rename("$fromdir/.lock/$fromfile","$todir/.lock/$tofile");
1085            try_dir("$todir/.bak");
1086            for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1087                    try_rename("$fromdir/.bak/$i/$fromfile","$todir/.bak/$i/$tofile");
1088          }          }
1089  }  }
1090    
1091    
1092  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1093    
1094  // recursivly delete directory  // recursivly delete directory
# Line 1148  function DisplayChangeLog($day) { Line 1127  function DisplayChangeLog($day) {
1127          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1128          $logarr = array();          $logarr = array();
1129          while($line = fgetcsv($log,255,"\t")) {          while($line = fgetcsv($log,255,"\t")) {
1130                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60))) {                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1131                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1132                  }                  }
1133          }          }
1134          fclose($log);          fclose($log);
1135          $cl1=" class=lst"; $cl2="";          $cl1=" class=LST"; $cl2="";
1136          print "<table border=0 width=100%>\n";          print "<table border=0 width=100%>\n";
1137          while ($e = array_shift($logarr)) {          while ($e = array_shift($logarr)) {
1138                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;                  $cl=$cl1; $cl1=$cl2; $cl2=$cl;
# Line 1184  function DisplayChangeLog($day) { Line 1163  function DisplayChangeLog($day) {
1163          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1164          // creation if password not yet set.          // creation if password not yet set.
1165          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1166          if ($HASH != "") {  
1167                  CreateHash($USER, $PW) ;          $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
1168                  exit ;          if (! file_exists($htusers_file)) {
1169                    if (is_writeable(dirname($SCRIPT_FILENAME))) {
1170                            $htusers=fopen($htusers_file,"a+");
1171                            fputs($htusers,"# Change owner of $htusers_file to root !!\n");
1172                            fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");
1173                            fclose($htusers);
1174                            Error("Proto user file created!","Please edit <tt>$htusers_file</tt> and set it correct permissions (<B>not writable by web server as it is now!</b>). You can add users using <tt>adduser.pl</tt> script!");
1175                            exit;
1176                    } else {
1177                            Error("Can't create proto user file!","Please make directory <tt>".dirname($htusers_file)."</tt> writable or create <tt>.htusers</tt> file by hand using <tt>adduser.pl</tt> script!");
1178                            exit;
1179                    }
1180          }          }
1181            $htusers=fopen($htusers_file,"r");
1182            while($user = fgetcsv($htusers,255,":")) {
1183                    if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
1184                            $gblUserName=$user[1];
1185                            $gblPw=$user[2];
1186                            if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {
1187                                    require("$gblIncDir/$gblPw.php");
1188                                    if ($gblPw($user)) {
1189                                            $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1190                                    } else {
1191                                            $gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW);
1192                                    }
1193                            }
1194                            $gblEmail=$user[3];
1195                            continue ;
1196                    }
1197            }
1198            fclose($htusers);
1199    
1200          // authentication if $gblAuth == true          // authentication failure
1201          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1202                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
1203                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1204                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1205                  NoEntry() ;                  NoEntry() ;
1206                  exit ;                  exit ;
# Line 1215  function DisplayChangeLog($day) { Line 1223  function DisplayChangeLog($day) {
1223          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1224    
1225          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1226          // i.e. /siteman          // i.e. /docman
1227    
1228          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1229          // i.e. /home/httpd/html/siteman          // i.e. /home/httpd/html/docman
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);
1248    
1249          switch ($POSTACTION) {          switch ($POSTACTION) {
1250          case "UPLOAD" :          case "UPLOAD" :
1251                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1235  function DisplayChangeLog($day) { Line 1254  function DisplayChangeLog($day) {
1254                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1255                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1256                  $source = $FN ;                  $source = $FN ;
1257                    if (! file_exists($source)) {
1258                            Error("You must select file with browse to upload it!");
1259                    }
1260                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1261                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/$FN_name" ;
1262                  } else {                  } else {
# Line 1267  function DisplayChangeLog($day) { Line 1289  function DisplayChangeLog($day) {
1289    
1290          case "SAVE" :          case "SAVE" :
1291                  $path = $gblFsRoot . $RELPATH ;                  $path = $gblFsRoot . $RELPATH ;
1292                    $path=stripSlashes($path);
1293                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1294                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1295                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 1274  function DisplayChangeLog($day) { Line 1297  function DisplayChangeLog($day) {
1297                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1298                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1299                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1300                    $FILEDATA=stripSlashes($FILEDATA);
1301                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1302                  fclose($fh) ;                  fclose($fh) ;
1303                  clearstatcache() ;                  clearstatcache() ;
# Line 1297  function DisplayChangeLog($day) { Line 1321  function DisplayChangeLog($day) {
1321  // this functionality is doubled in DetailView().  // this functionality is doubled in DetailView().
1322  // better keep it here altogether  // better keep it here altogether
1323  // chmod perms to $gblFilePerms  // chmod perms to $gblFilePerms
1324                          if ( file_exists($path) && !is_writable($path) )                          if ( file_exists($path) && !is_writeable($path) )
1325                                  Error("File not writable", $relPath) ;                                  Error("File not writable", $relPath) ;
1326                          $fh = fopen($path, "w+") ;                          $fh = fopen($path, "w+") ;
1327                          if ($fh) {                          if ($fh) {
# Line 1369  function DisplayChangeLog($day) { Line 1393  function DisplayChangeLog($day) {
1393                  if ( $CONFIRM != "on" ) break ;                  if ( $CONFIRM != "on" ) break ;
1394    
1395                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");                  Logit("$fsDir/$FN","renamed $FN to $NEWNAME");
1396                  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");  
                 }  
   
1397                  break ;                  break ;
1398    
1399          case "NOTE" :            case "NOTE" :  
# Line 1408  function DisplayChangeLog($day) { Line 1425  function DisplayChangeLog($day) {
1425          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1426          // default : display directory $D          // default : display directory $D
1427    
         $F=stripSlashes($F);  
   
1428          switch ($A) {          switch ($A) {
1429          case "U" :          case "U" :
1430                  // upload to $relDir                  // upload to $relDir
1431                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1432                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1433                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1434                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1435                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1436                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1437                  EndHTML() ;                  EndHTML() ;
1438                  exit ;                  exit ;
1439          case "E" :          case "E" :
1440                    $F=stripSlashes($F);
1441                  // detail of $relDir/$F                  // detail of $relDir/$F
1442                  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) ;
1443                  exit ;                  exit ;
1444          case "C" :          case "C" :
1445                    $F=stripSlashes($F);
1446                  // listing of $relDir/$F                  // listing of $relDir/$F
1447                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1448                  exit ;                  exit ;
# Line 1433  function DisplayChangeLog($day) { Line 1450  function DisplayChangeLog($day) {
1450                  // checkout                  // checkout
1451                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1452                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1453                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: $webRoot".urlpath("$relDir/$F"));
1454                  exit;                  exit;
1455          case "Ci" :          case "Ci" :
1456                    $F=stripSlashes($F);
1457                  // upload && update to $relDir                  // upload && update to $relDir
1458                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1459                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1460                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1461                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1462                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1463                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1464                  EndHTML() ;                  EndHTML() ;
# Line 1449  function DisplayChangeLog($day) { Line 1467  function DisplayChangeLog($day) {
1467                  // view                  // view
1468                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1469                  header("Content-Disposition: attachment; filename=$F" );                  header("Content-Disposition: attachment; filename=$F" );
1470                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: $webRoot".urlpath("$relDir/$F"));
1471                  exit;                  exit;
1472          case "Ch" :          case "Ch" :
1473                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.35

  ViewVC Help
Powered by ViewVC 1.1.26