/[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.9 by dpavlin, Fri Aug 4 10:43:23 2000 UTC revision 1.29 by dpavlin, Fri Jan 26 09:32:48 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    
62  */  */
63    
64  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
# Line 78  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 = "/data/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) {          $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";
87                  $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";          if (! file_exists($htusers_file)) {
88                  if (! file_exists($htusers_file)) {                  $htusers=fopen($htusers_file,"a+");
89                          $htusers=fopen($htusers_file,"a+");                  fputs($htusers,"# Change owner of $htusers_file to root !!\n");
90                          fputs($htusers,"# Change owner of $htusers_file to root !!\n");                  fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");
91                          fputs($htusers,"demo:full name:md5_hash\n");                  fclose($htusers);
92                          fclose($htusers);          }
93                  }          $htusers=fopen($htusers_file,"r");
94                  $htusers=fopen($htusers_file,"r");          while($user = fgetcsv($htusers,255,":")) {
95                  while($user = fgetcsv($htusers,255,":")) {                  if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {
96                          if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {                          $gblUserName=$user[1];
97                                  $gblUserName=$user[1];                          $gblPw=$user[2];
98                                  $gblPw=$user[2];                          if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {
99                                  continue ;                                  require("$gblIncDir/$gblPw.php");
100                                    if ($gblPw($user)) {
101                                            $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);
102                                    }
103                          }                          }
104                            $gblEmail=$user[3];
105                            continue ;
106                  }                  }
                 fclose($htusers);  
107          }          }
108            fclose($htusers);
109    
110            // date format
111  //      $gblDateFmt="D, F d, Y";  //      $gblDateFmt="D, F d, Y";
 //      $gblTimeFmt="g:i:sA";  
   
112          $gblDateFmt="Y-m-d";          $gblDateFmt="Y-m-d";
113    
114            // time format
115    //      $gblTimeFmt="g:i:sA";
116          $gblTimeFmt="H:i:s";          $gblTimeFmt="H:i:s";
117    
118  // Number of backup files to keep          // Number of backup files to keep
119          $gblNumBackups=5;          $gblNumBackups=3;
120    
121            // show red star if newer than ... days
122            $gblModDays=1;
123    
124          // choose GifIcon below unless you have the M$          // choose GifIcon below unless you have the M$
125          // WingDings font installed on your system          // WingDings font installed on your system
126    
127          $gblIcon = "GifIcon" ;          // MockIcon or GifIcon          $gblIcon="GifIcon";             // MockIcon or GifIcon
128    
129          // the directory below should be /icons/ or /icons/small/          // the directory below should be /icons/ or /icons/small/
130          // on Apache; a set of icons is included in the distribution          // on Apache; a set of icons is included in the distribution
131    
132          $gblIconLocation = "/icons/" ;          $gblIconLocation="/icons/";
133    
134          // files you want to be able to edit in text mode          // files you want to be able to edit in text mode
135          // and view with (primitive) syntax highlighting          // and view with (primitive) syntax highlighting
# Line 148  TODO: Line 148  TODO:
148    
149  function StartHTML($title,$text="") {  function StartHTML($title,$text="") {
150    
151          $title = "Site Manager " . $title ;          $title = "Document Manager " . $title ;
152          $host  = $GLOBALS["HTTP_HOST"] ;          $host  = $GLOBALS["HTTP_HOST"] ;
153          $self  = $GLOBALS["PHP_SELF"] ;          $self  = $GLOBALS["PHP_SELF"] ;
154  ?>  ?>
# Line 293  echo($fstr) ; ?></TEXTAREA> Line 293  echo($fstr) ; ?></TEXTAREA>
293    
294  <?php  <?php
295          }          }
296          if ( !$file_lock && strstr(join(" ",$gblImages),$ext) ) {            if ( !$file_lock && $ext!="" && strstr(join(' ',$gblImages),$ext) ) {  
297                  $info  = getimagesize($fsPath) ;                  $info  = getimagesize($fsPath) ;
298                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;                  $tstr = "<IMG SRC=\"".urlpath($relPath)."\" BORDER=0 " ;
299                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;                  $tstr .= $info[3] . " ALT=\"" . $fn . " - " ;
# Line 361  echo($fstr) ; ?></TEXTAREA> Line 361  echo($fstr) ; ?></TEXTAREA>
361  </FORM>  </FORM>
362    
363  <?php  <?php
           
364    
365          $logname=dirname("$fsDir/$fn")."/.log/".basename("$fsDir/$fn");          $name=basename("$fsDir/$fn");
366            $logname=dirname("$fsDir/$fn")."/.log/$name";
367            $bakdir=dirname("$fsDir/$fn")."/.bak";
368          if (file_exists($logname)) {          if (file_exists($logname)) {
                 print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";  
369                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
370                  $cl1=" class=lst"; $cl2="";                  $cl1=" class=LST"; $cl2="";
371                    $logarr = array();
372                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,255,"\t")) {
373                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
374                          print "<tr><td$cl>$line[0]</td><td$cl>$line[1]</td><td$cl>$line[2]</td><td$cl>$line[3]</td></tr>\n";                          array_unshift($logarr,array($cl,$line[0],$line[1],$line[2],$line[3]));
375                  }                  }
376                  fclose($log);                  fclose($log);
377                    print "<hr><br><b>CHANGES TO THIS FILE</b><br><table border=0 width=100%>\n";
378                    $bakcount = 0;  // start from 0, skip fist backup (it's current)
379                    while ($e = array_shift($logarr)) {
380                            if (strstr($e[4],"upload")) {
381                                    if (file_exists("$bakdir/$bakcount/$name")) {
382                                            $e[4]="<a href=\"".urlpath(dirname($relPath)."/.bak/$bakcount/$name")."\">$e[4]</a>";
383                                    }
384                                    $bakcount++;
385                            }
386                            print "<tr><td$e[0]>$e[1]</td><td$e[0]>$e[2]</td><td$e[0]>$e[3]</td><td$e[0]>$e[4]</td></tr>\n";
387                    }
388                  print "</table>";                  print "</table>";
389          }          }
390    
# Line 628  function GifIcon($txt) { Line 640  function GifIcon($txt) {
640    
641  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
642    
643          global $gblEditable, $gblIcon ;          global $gblEditable, $gblIcon, $gblModDays ;
644    
645          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
646          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {          if (isset($GLOBALS["HTTPS"]) && $GLOBALS["HTTPS"] == "on") {
647                  $webRoot  = "https://" . $GLOBALS["SERVER_NAME"] ;                  $webRoot  = "https://" . $GLOBALS["HTTP_HOST"] ;
648          } else {          } else {
649                  $webRoot  = "http://" . $GLOBALS["SERVER_NAME"] ;                  $webRoot  = "http://" . $GLOBALS["HTTP_HOST"] ;
650          }          }
651          $fsDir    = $fsRoot . $relDir . "/" ; // current directory          $fsDir    = $fsRoot . $relDir . "/" ; // current directory
652    
# Line 677  function Navigate($fsRoot,$relDir) { Line 689  function Navigate($fsRoot,$relDir) {
689                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";                  $text .= ", <a href=$self?D=".urlencode($relDir)."&show_deleted=1>undelete</a>";
690          }          }
691          $text .= " or revise files on this web site." ;          $text .= " or revise files on this web site." ;
692            $text .= "<br>Examine list of files <a href=\"$self?A=Ch1\">changed in last day</a> or <a href=\"$self?A=Ch\">all changes</a>.";
693          StartHTML("(Navigate)",$text) ;          StartHTML("(Navigate)",$text) ;
694    
695          echo "<TABLE BORDER=0 CELLPADDING=2          echo "<TABLE BORDER=0 CELLPADDING=2
# Line 743  function Navigate($fsRoot,$relDir) { Line 756  function Navigate($fsRoot,$relDir) {
756    
757                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);                  $info_url=$self."?A=E&F=".urlencode($file)."&D=".urlencode($relDir);
758    
759                  if ( ($mod + 30*86400) > time() ) {                  if ( ($mod + $gblModDays*86400) > time() ) {
760                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;                          $a  = "<SPAN CLASS=RED TITLE=\"Newer" ;
761                          $a .= " than 30 days\"> * </SPAN>" ;                          $a .= " than $gblModDays days\"> * </SPAN>" ;
762                  }                  }
763    
764                  $file_lock=CheckLock($path);                  $file_lock=CheckLock($path);
# Line 810  function Navigate($fsRoot,$relDir) { Line 823  function Navigate($fsRoot,$relDir) {
823    
824  <?php  <?php
825            }  // iterate over files            }  // iterate over files
826          }  // end if no files          } else {  // end if no files
827    ?>
828     <TR><TD></TD><TD COLSPAN=5 CLASS=LST>
829      No files in this directory
830     </TD></TR>
831    <?
832            }
833    
834          if ($emptyDir) {          if ($emptyDir) {
835  ?>  ?>
# Line 830  function Navigate($fsRoot,$relDir) { Line 849  function Navigate($fsRoot,$relDir) {
849    
850  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>
851    
852  <TR><TD></TD><TD COLSPAN=5>  <?
853  To just view file without editing, select it's filename (<b>don't edit files which are opened this way!</b>)<br>  if (file_exists(".info.inc")) {
854  To <b>edit</b> file select <?= $gblIcon("checkout") ?> to check-out          print "<TR><TD></TD><TD COLSPAN=5>";
855  and edit it locally. After editing is over, select filename or <?= $gblIcon("checkin") ?> to check-in (update copy of file on server).<br>          include(".info.inc");
856  <by>If you select icon left from filename, you will get detailed information          print "</TD></TR>
857  about file, as well as delete, rename and annotation options.          <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>";
858  </TD></TR>  }
859    ?>
 <TR><TD></TD><TD COLSPAN=5><HR></TD></TR>  
860    
861  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
862  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW  <TR><TD></TD><TD COLSPAN=5 CLASS=BAR>CREATE NEW
# Line 860  about file, as well as delete, rename an Line 878  about file, as well as delete, rename an
878    
879  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
880    
881  function UploadPage($fsRoot, $relDir, $filename) {  function UploadPage($fsRoot, $relDir, $filename="") {
882    
883          $self = $GLOBALS["PHP_SELF"] ;          $self = $GLOBALS["PHP_SELF"] ;
884          if ($relDir == "") $relDir = "/" ;          if ($relDir == "") $relDir = "/" ;
# Line 870  function UploadPage($fsRoot, $relDir, $f Line 888  function UploadPage($fsRoot, $relDir, $f
888  <FORM ENCTYPE="multipart/form-data" METHOD="POST"  <FORM ENCTYPE="multipart/form-data" METHOD="POST"
889   ACTION="<?= $self ?>">   ACTION="<?= $self ?>">
890  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>  DESTINATION DIRECTORY:<B><?= " " . $relDir ?></B>
891  <? if (isset($filename)) { ?>  <? if (isset($filename) && $filename!="") { ?>
892  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>  <br>DESTINATION FILE:<B><?= " " . $filename ?></B>
893  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">  <INPUT TYPE="HIDDEN" NAME="FILENAME" VALUE="<?= $filename ?>">
894  <? } ?>  <? } ?>
# Line 905  function Error($title,$text="") { Line 923  function Error($title,$text="") {
923    
924  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
925    
 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  
   
 //////////////////////////////////////////////////////////////////  
   
926  function NoEntry() {  function NoEntry() {
927    
928          $user = $GLOBALS["PHP_AUTH_USER"] ;          $user = $GLOBALS["PHP_AUTH_USER"] ;
# Line 937  function NoEntry() { Line 932  function NoEntry() {
932          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
933          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
934          StartHTML($title,$text) ;          StartHTML($title,$text) ;
 ?>  
935    
 <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  
936          EndHTML() ;          EndHTML() ;
937          exit ;          exit ;
938  }  }
939    
940  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
941    
942  function Logit($target,$msg) {  function LogIt($target,$msg) {
943    
944          $dir=dirname($target);          $dir=dirname($target);
945          if (! file_exists($dir."/.log")) {          if (! file_exists($dir."/.log")) {
# Line 977  function Logit($target,$msg) { Line 959  function Logit($target,$msg) {
959    
960  function WriteNote($target,$msg) {  function WriteNote($target,$msg) {
961    
962            $target=stripSlashes($target);
963          $dir=dirname($target);          $dir=dirname($target);
964          if (! file_exists($dir."/.note")) {          if (! file_exists($dir."/.note")) {
965                  mkdir($dir."/.note",0700);                  mkdir($dir."/.note",0700);
# Line 993  function WriteNote($target,$msg) { Line 976  function WriteNote($target,$msg) {
976    
977  function ReadNote($target) {  function ReadNote($target) {
978    
979            $target=stripSlashes($target);
980          $dir=dirname($target);          $dir=dirname($target);
981          $file=basename($target);          $file=basename($target);
982          $msg="";          $msg="";
# Line 1009  function ReadNote($target) { Line 993  function ReadNote($target) {
993    
994  function MoveTo($source,$folder) {  function MoveTo($source,$folder) {
995    
996            $source=stripSlashes($source);
997          $file=basename($source);          $file=basename($source);
998          if (! file_exists($folder)) {          if (! file_exists($folder)) {
999                  mkdir($folder,0700);                  mkdir($folder,0700);
# Line 1022  function MoveTo($source,$folder) { Line 1007  function MoveTo($source,$folder) {
1007    
1008  function Lock($target) {  function Lock($target) {
1009    
1010            $target=stripSlashes($target);
1011          $dir=dirname($target);          $dir=dirname($target);
1012          if (! file_exists($dir."/.lock")) {          if (! file_exists($dir."/.lock")) {
1013                  mkdir($dir."/.lock",0700);                  mkdir($dir."/.lock",0700);
# Line 1042  function Lock($target) { Line 1028  function Lock($target) {
1028    
1029  function CheckLock($target) {  function CheckLock($target) {
1030    
1031            $target=stripSlashes($target);
1032          $dir=dirname($target);          $dir=dirname($target);
1033          $file=basename($target);          $file=basename($target);
1034          $msg=0;          $msg=0;
# Line 1056  function CheckLock($target) { Line 1043  function CheckLock($target) {
1043    
1044  function Unlock($target) {  function Unlock($target) {
1045    
1046            $target=stripSlashes($target);
1047          $dir=dirname($target);          $dir=dirname($target);
1048          $file=basename($target);          $file=basename($target);
1049          if (file_exists($dir."/.lock/$file")) {          if (file_exists($dir."/.lock/$file")) {
# Line 1086  function safe_rename($from,$to) { Line 1074  function safe_rename($from,$to) {
1074    
1075  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1076    
1077    // recursivly delete directory
1078    
1079    function rrmdir($dir) {
1080            $handle=opendir($dir);
1081            while ($file = readdir($handle)) {
1082                    if ($file != "." && $file != "..") {
1083                            if (is_dir("$dir/$file"))
1084                                    rrmdir("$dir/$file");
1085                            else
1086                                    if (! @unlink("$dir/$file")) return(0);
1087                    }
1088            }
1089            closedir($handle);
1090            return @rmdir($dir);
1091    }
1092    
1093    //////////////////////////////////////////////////////////////////
1094    
1095    function ChangeLog($target,$msg) {
1096    
1097            global $gblFsRoot;
1098            $log=fopen("$gblFsRoot/.changelog","a+");
1099            if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1100                    $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1101            fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1102            fclose($log);
1103    
1104    }
1105    
1106    function DisplayChangeLog($day) {
1107    
1108            global $gblFsRoot;
1109            if (!file_exists("$gblFsRoot/.changelog")) return;
1110            $log=fopen("$gblFsRoot/.changelog","r");
1111            $logarr = array();
1112            while($line = fgetcsv($log,255,"\t")) {
1113                    if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1114                            array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1115                    }
1116            }
1117            fclose($log);
1118            $cl1=" class=LST"; $cl2="";
1119            print "<table border=0 width=100%>\n";
1120            while ($e = array_shift($logarr)) {
1121                    $cl=$cl1; $cl1=$cl2; $cl2=$cl;
1122                    $date = date("$GLOBALS[gblDateFmt]", $e[0]);
1123                    $time = date("$GLOBALS[gblTimeFmt]", $e[0]);
1124                    $dir = dirname($e[1]);
1125                    $file = basename($e[1]);
1126                    print "<tr><td$cl>$date</td><td$cl>$time</td><td$cl><a href=\"$GLOBALS[PHP_SELF]?D=".urlencode($dir)."\">$dir</a>/$file</td><td$cl>$e[2]</td><td$cl>$e[3]</td></tr>\n";
1127            }
1128            print "</table>";
1129            print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1130    }
1131    
1132    //////////////////////////////////////////////////////////////////
1133    
1134  // MAIN PROGRAM  // MAIN PROGRAM
1135  // ============  // ============
1136  // query parameters: capital letters  // query parameters: capital letters
# Line 1101  function safe_rename($from,$to) { Line 1146  function safe_rename($from,$to) {
1146          // forks before authentication: style sheet and hash          // forks before authentication: style sheet and hash
1147          // creation if password not yet set.          // creation if password not yet set.
1148          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
         if ($HASH != "") {  
                 CreateHash($USER, $PW) ;  
                 exit ;  
         }  
1149    
1150          // authentication if $gblAuth == true          // authentication failure
1151          if ( $gblAuth && $gblHash($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1152                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin ) {
1153                  header("WWW-authenticate: basic realm=\"$SERVER_NAME\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1154                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1155                  NoEntry() ;                  NoEntry() ;
1156                  exit ;                  exit ;
# Line 1132  function safe_rename($from,$to) { Line 1173  function safe_rename($from,$to) {
1173          // i.e. below $gblFsRoot.          // i.e. below $gblFsRoot.
1174    
1175          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1176          // i.e. /siteman          // i.e. /docman
1177    
1178          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;              $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1179          // i.e. /home/httpd/html/siteman          // i.e. /home/httpd/html/docman
1180    
1181          $gblFsRoot = substr($fsScriptDir,0,          // start on server root
1182            strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1183            // or on script root
1184            $gblFsRoot = $fsScriptDir;
1185          // i.e. /home/httpd/html          // i.e. /home/httpd/html
1186    
1187          $fsDir = $gblFsRoot . $relDir ; // current directory          $fsDir = $gblFsRoot . $relDir ; // current directory
1188          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;          if ( !is_dir($fsDir) ) Error("Dir not found",$relDir) ;
1189            
1190            $FN=stripSlashes($FN);
1191    
1192          switch ($POSTACTION) {          switch ($POSTACTION) {
1193          case "UPLOAD" :          case "UPLOAD" :
1194                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;                  if (!is_writeable($fsDir)) Error("Write denied",$relDir) ;
# Line 1152  function safe_rename($from,$to) { Line 1197  function safe_rename($from,$to) {
1197                  // TODO : should rather check for escapeshellcmds                  // TODO : should rather check for escapeshellcmds
1198                  // but maybe RFC 18xx asserts safe filenames ....                  // but maybe RFC 18xx asserts safe filenames ....
1199                  $source = $FN ;                  $source = $FN ;
1200                    if (! file_exists($source)) {
1201                            Error("You must select file with browse to upload it!");
1202                    }
1203                  if (! isset($FILENAME)) {       // from update file                  if (! isset($FILENAME)) {       // from update file
1204                          $target = "$fsDir/$FN_name" ;                          $target = "$fsDir/$FN_name" ;
1205                  } else {                  } else {
# Line 1179  function safe_rename($from,$to) { Line 1227  function safe_rename($from,$to) {
1227                  if (isset($FILENAME)) {                  if (isset($FILENAME)) {
1228                          Unlock($target);                          Unlock($target);
1229                  }                  }
1230                    ChangeLog($target,"updated");
1231                  break ;                  break ;
1232    
1233          case "SAVE" :          case "SAVE" :
1234                  $path = $gblFsRoot . escapeshellcmd($RELPATH) ;                  $path = $gblFsRoot . $RELPATH ;
1235                    $path=stripSlashes($path);
1236                  $writable = is_writeable($path) ;                  $writable = is_writeable($path) ;
1237                  $legaldir = is_writeable(dirname($path)) ;                  $legaldir = is_writeable(dirname($path)) ;
1238                  $exists   = (file_exists($path)) ? 1 : 0 ;                  $exists   = (file_exists($path)) ? 1 : 0 ;
# Line 1190  function safe_rename($from,$to) { Line 1240  function safe_rename($from,$to) {
1240                  if (!($writable || (!$exists && $legaldir)))                  if (!($writable || (!$exists && $legaldir)))
1241                          Error("Write denied",$RELPATH) ;                          Error("Write denied",$RELPATH) ;
1242                  $fh = fopen($path, "w") ;                  $fh = fopen($path, "w") ;
1243                    $FILEDATA=stripSlashes($FILEDATA);
1244                  fwrite($fh,$FILEDATA) ;                  fwrite($fh,$FILEDATA) ;
1245                  fclose($fh) ;                  fclose($fh) ;
1246                  clearstatcache() ;                  clearstatcache() ;
1247                  Logit($path,"saved changes");                  Logit($path,"saved changes");
1248                    ChangeLog($path,"saved changes");
1249                  break ;                  break ;
1250    
1251          case "CREATE" :          case "CREATE" :
# Line 1224  function safe_rename($from,$to) { Line 1276  function safe_rename($from,$to) {
1276                          }                          }
1277                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;                          $tstr = "$PHP_SELF?A=E&D=".urlencode($relDir)."&F=".urlencode($FN) ;
1278                          header("Location: " . $tstr) ;                          header("Location: " . $tstr) ;
1279                            ChangeLog($target,"created");
1280                          exit ;                          exit ;
1281                  }                  }
1282                  break ;                  break ;
# Line 1256  function safe_rename($from,$to) { Line 1309  function safe_rename($from,$to) {
1309                          }                          }
1310                  }                  }
1311                  else {  // delete directory                  else {  // delete directory
1312                    if ( ! @rmdir($fsDir) ) {                    if ( ! @rrmdir($fsDir) ) {
1313                      Error("Rmdir failed", $tstr . $fsDir) ;                      Error("Rmdir failed", $tstr . $fsDir) ;
1314                    }                    }
1315                    else {                    else {
# Line 1287  function safe_rename($from,$to) { Line 1340  function safe_rename($from,$to) {
1340                  safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");                  safe_rename("$fsDir/.log/$FN","$fsDir/.log/$NEWNAME");
1341                  safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");                  safe_rename("$fsDir/.note/$FN","$fsDir/.note/$NEWNAME");
1342                  safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");                  safe_rename("$fsDir/.lock/$FN","$fsDir/.lock/$NEWNAME");
1343                    for($i=0;$i<=$GLOBALS[gblNumBackups];$i++) {
1344                            safe_rename("$fsDir/.bak/$i/$FN","$fsDir/.bak/$i/$NEWNAME");
1345                    }
1346    
1347                  break ;                  break ;
1348    
# Line 1318  function safe_rename($from,$to) { Line 1374  function safe_rename($from,$to) {
1374          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1375          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1376          // default : display directory $D          // default : display directory $D
1377            
1378          switch ($A) {          switch ($A) {
1379          case "U" :          case "U" :
1380                  // upload to $relDir                  // upload to $relDir
1381                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1382                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1383                  $text  = "Use this page to upload a single " ;                  $text  = "Use this page to upload a single " ;
1384                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1385                  StartHTML("(Upload Page)", $text) ;                  StartHTML("(Upload Page)", $text) ;
1386                  UploadPage($gblFsRoot, $relDir) ;                  UploadPage($gblFsRoot, $relDir) ;
1387                  EndHTML() ;                  EndHTML() ;
1388                  exit ;                  exit ;
1389          case "E" :          case "E" :
1390                    $F=stripSlashes($F);
1391                  // detail of $relDir/$F                  // detail of $relDir/$F
1392                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;                  if (is_file("$gblFsRoot/$relDir/$F")) DetailPage($gblFsRoot, $relDir, $F) ;
1393                  exit ;                  exit ;
1394          case "C" :          case "C" :
1395                    $F=stripSlashes($F);
1396                  // listing of $relDir/$F                  // listing of $relDir/$F
1397                  DisplayCode($gblFsRoot, $relDir, $F) ;                  DisplayCode($gblFsRoot, $relDir, $F) ;
1398                  exit ;                  exit ;
1399          case "Co" :          case "Co" :
1400                  // checkout                  // checkout
1401                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1402                    header("Content-Disposition: attachment; filename=$F" );
1403                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: ".urlpath("$relDir/$F"));
1404                  exit;                  exit;
1405          case "Ci" :          case "Ci" :
1406                    $F=stripSlashes($F);
1407                  // upload && update to $relDir                  // upload && update to $relDir
1408                  if (!is_writeable($gblFsRoot . $relDir))                  if (!is_writeable($gblFsRoot . $relDir))
1409                          Error("Write access denied",$relDir) ;                          Error("Write access denied",$relDir) ;
1410                  $text  = "Use this page to update a single " ;                  $text  = "Use this page to update a single " ;
1411                  $text .= "file to <B>$SERVER_NAME</B>." ;                  $text .= "file to <B>$HTTP_HOST</B>." ;
1412                  StartHTML("(Update file Page)", $text) ;                  StartHTML("(Update file Page)", $text) ;
1413                  UploadPage($gblFsRoot, $relDir, $F) ;                  UploadPage($gblFsRoot, $relDir, $F) ;
1414                  EndHTML() ;                  EndHTML() ;
# Line 1356  function safe_rename($from,$to) { Line 1416  function safe_rename($from,$to) {
1416          case "V" :          case "V" :
1417                  // view                  // view
1418                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1419                    header("Content-Disposition: attachment; filename=$F" );
1420                  Header("Location: ".urlpath("$relDir/$F"));                  Header("Location: ".urlpath("$relDir/$F"));
1421                  exit;                  exit;
1422            case "Ch" :
1423                    StartHTML("(File changes)","All changes chronologicaly...");
1424                    DisplayChangeLog(0);    // all
1425                    EndHTML() ;
1426                    exit;
1427            case "Ch1" :
1428                    StartHTML("(File changes)","Changes to files in last day...");
1429                    DisplayChangeLog(1);
1430                    EndHTML() ;
1431                    exit;
1432          }          }
1433    
1434          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.29

  ViewVC Help
Powered by ViewVC 1.1.26