/[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.40 by dpavlin, Fri Apr 6 08:46:42 2001 UTC revision 1.50 by dpavlin, Sat Dec 15 20:33:37 2001 UTC
# Line 78  TODO: Line 78  TODO:
78          // from where to include auth_*.php modules?          // from where to include auth_*.php modules?
79          $gblIncDir = "/home/httpd/docman";          $gblIncDir = "/home/httpd/docman";
80    
81            // 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          // username/password should not be system          // username/password should not be system
87          // usernames/passwords !!          // usernames/passwords !!
88    
# Line 120  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 = "Document Manager " . $title ;          $title = "Document Manager " . $title ;
# Line 132  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 151  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            $url.="&AU=${PHP_AUTH_USER}|AP=${PHP_AUTH_PW}|";
191    ?>
192    <small> [<a href="<?= $url ?>"><?= $url_title ?></a>]</small>
193  </B>  </B>
194  <BR>ANYPORTAL(php) Site Manager  <BR><small>
195  <br><small>  Document Manager <?= $gblVersion ?>, based on ANYPORTAL(php) Site Manager
196    <br>
197  &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,  &copy; 1999 by <A HREF="http://www.anyportal.com">ANYPORTAL</A>,
198  &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>,
199  &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 354  echo($fstr) ; ?></TEXTAREA> Line 386  echo($fstr) ; ?></TEXTAREA>
386                  $log=fopen($logname,"r");                  $log=fopen($logname,"r");
387                  $cl1=" class=LST"; $cl2="";                  $cl1=" class=LST"; $cl2="";
388                  $logarr = array();                  $logarr = array();
389                  while($line = fgetcsv($log,255,"\t")) {                  while($line = fgetcsv($log,512,"\t")) {
390                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;                          $cl=$cl1; $cl1=$cl2; $cl2=$cl;
391                          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]));
392                  }                  }
# Line 630  function GifIcon($txt) { Line 662  function GifIcon($txt) {
662    
663  function Navigate($fsRoot,$relDir) {  function Navigate($fsRoot,$relDir) {
664    
665          global $gblEditable, $gblIcon, $gblModDays, $webRoot ;          global $gblEditable, $gblIcon, $gblModDays, $webRoot, $gblHide ;
666    
667          $self     = $GLOBALS["PHP_SELF"] ;          $self     = $GLOBALS["PHP_SELF"] ;
668    
# Line 638  function Navigate($fsRoot,$relDir) { Line 670  function Navigate($fsRoot,$relDir) {
670    
671          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;          if (!is_dir($fsDir)) Error("Dir not found",$relDir) ;
672    
673            $hide_items=",$gblHide,";
674    
675          // read directory contents          // read directory contents
676          if ( !($dir = @opendir($fsDir)) )          if ( !($dir = @opendir($fsDir)) )
677                  Error("Read Access denied",$relDir) ;                  Error("Read Access denied",$relDir) ;
678          while ($item = readdir($dir)) {          while ($item = readdir($dir)) {
679                  if ( $item == ".." || $item == "." || substr($item,0,1) == "." ) continue ;                  if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
680                  if ( is_dir($fsDir . $item) ) {                  if ( is_dir($fsDir . $item) ) {
681                          $dirList[] = $item ;                          $dirList[] = $item ;
682                  } else if ( is_file($fsDir . $item) ) {                  } else if ( is_file($fsDir . $item) ) {
# Line 661  function Navigate($fsRoot,$relDir) { Line 695  function Navigate($fsRoot,$relDir) {
695          // scan deleted files          // scan deleted files
696          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {          if ( $GLOBALS[show_deleted] == 1 && ($dir = @opendir("$fsDir/.del")) ) {
697                  while ($item = readdir($dir)) {                  while ($item = readdir($dir)) {
698                          if ( substr($item,0,1) == "." ) continue ;                          if ( substr($item,0,1) == "." || strstr($hide_items,",$item,") ) continue ;
699                          $fileList[] = ".del/$item" ;                                      $fileList[] = ".del/$item" ;            
700                  }                  }
701                  closedir($dir) ;                  closedir($dir) ;
# Line 682  function Navigate($fsRoot,$relDir) { Line 716  function Navigate($fsRoot,$relDir) {
716                  CELLSPACING=3 WIDTH=\"100%\">" ;                  CELLSPACING=3 WIDTH=\"100%\">" ;
717    
718          // updir bar              // updir bar    
719          if ($fsDir != $fsRoot) {          if (chopsl($fsDir) != chopsl($fsRoot)) {
720                  $parent = dirname($relDir) ;                  $parent = dirname($relDir) ;
721                  if ($parent == "") $parent = "/" ;                  if ($parent == "") $parent = "/" ;
722  ?>  ?>
# Line 694  function Navigate($fsRoot,$relDir) { Line 728  function Navigate($fsRoot,$relDir) {
728  <?php  <?php
729          }          }
730    
731    function plural($name,$count) {
732            $out="$count $name";
733            if ($count > 1) {
734                    $out.="s";
735            }
736            return $out;
737    }
738    
739          // output subdirs          // output subdirs
740          if (sizeof($dirList) > 0) {          if (sizeof($dirList) > 0) {
741                  sort($dirList) ;                  sort($dirList) ;
742  ?>  ?>
743    
744  <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>  <TR><TD></TD><TD COLSPAN=2 CLASS=TOP>DIRECTORY NAME (<?= plural("dir",sizeof($dirList)) ?>)</TD><TD COLSPAN=3 CLASS=TOP>DIRECTORY NOTE</TR>
745    
746  <?php  <?php
747                  while (list($key,$dir) = each($dirList)) {                  while (list($key,$dir) = each($dirList)) {
# Line 724  function Navigate($fsRoot,$relDir) { Line 766  function Navigate($fsRoot,$relDir) {
766    
767  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>  <TR><TD></TD><TD COLSPAN=5><HR><B><?= $webRoot . $relDir ?>
768  </B></TD></TR>  </B></TD></TR>
769  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME</TD>  <TR><TD></TD><TD CLASS=TOP>DOCUMENT NAME (<?= plural("file",sizeof($fileList)) ?>)</TD>
770  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>  <TD><?= $gblIcon("blank").$gblIcon("blank") ?></TD>
771  <TD CLASS=TOP>NOTE</TD>  <TD CLASS=TOP>NOTE</TD>
772  <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 822  function Navigate($fsRoot,$relDir) { Line 864  function Navigate($fsRoot,$relDir) {
864  <?  <?
865          }          }
866    
867          if ($emptyDir) {          if ($emptyDir && $relDir != "") {
868  ?>  ?>
869    
870  <FORM METHOD="POST" ACTION="<?= $self ?>">  <FORM METHOD="POST" ACTION="<?= $self ?>">
# Line 923  function NoEntry() { Line 965  function NoEntry() {
965    
966          $title = "(401 Unauthorized)" ;          $title = "(401 Unauthorized)" ;
967          $text  = "No trespassing !" ;          $text  = "No trespassing !" ;
968    
969            global $PHP_AUTH_USER,$PHP_AUTH_PW,$gblPw,$relogin;
970          StartHTML($title,$text) ;          StartHTML($title,$text) ;
971    
972          EndHTML() ;          EndHTML() ;
# Line 977  function ReadNote($target) { Line 1021  function ReadNote($target) {
1021                  $msg=fgets($note,4096);                  $msg=fgets($note,4096);
1022                  fclose($note);                  fclose($note);
1023          }          }
1024          return StripSlashes($msg);          return HtmlSpecialChars(StripSlashes($msg));
1025    
1026  }  }
1027    
# Line 1118  function ChangeLog($target,$msg) { Line 1162  function ChangeLog($target,$msg) {
1162          $log=fopen("$gblFsRoot/.changelog","a+");          $log=fopen("$gblFsRoot/.changelog","a+");
1163          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)          if (substr($target,0,strlen($gblFsRoot)) == $gblFsRoot)
1164                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));                  $target=substr($target,strlen($gblFsRoot),strlen($target)-strlen($gblFsRoot));
1165            $msg=str_replace("\t"," ",$msg);
1166          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");          fputs($log,time()."\t$target\t$GLOBALS[gblUserName]\t$msg\n");
1167          fclose($log);          fclose($log);
1168    
# Line 1129  function DisplayChangeLog($day) { Line 1174  function DisplayChangeLog($day) {
1174          if (!file_exists("$gblFsRoot/.changelog")) return;          if (!file_exists("$gblFsRoot/.changelog")) return;
1175          $log=fopen("$gblFsRoot/.changelog","r");          $log=fopen("$gblFsRoot/.changelog","r");
1176          $logarr = array();          $logarr = array();
1177          while($line = fgetcsv($log,255,"\t")) {          while($line = fgetcsv($log,512,"\t")) {
1178                    $line[0] .= sizeof($line);
1179                    while (sizeof($line) > 4) {
1180                            $tmp = array_pop($line);
1181                            $line.=" $tmp";
1182                    }
1183                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {                  if ($day!=1 || ($day==1 && (time()-$line[0] < 24*60*60))) {
1184                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));                          array_unshift($logarr,array($line[0],$line[1],$line[2],$line[3]));
1185                  }                  }
# Line 1151  function DisplayChangeLog($day) { Line 1201  function DisplayChangeLog($day) {
1201    
1202  //////////////////////////////////////////////////////////////////  //////////////////////////////////////////////////////////////////
1203    
1204    function Download($path) {
1205            global $HTTP_USER_AGENT;
1206            $file=basename($path);
1207            $size = filesize($path);
1208            //header("Content-Type: application/octet-stream");
1209            header("Content-Type: application/force-download");
1210            header("Content-Length: $size");
1211            // IE5.5 just downloads index.php if we don't do this
1212            if(preg_match("/MSIE 5.5/", $HTTP_USER_AGENT)) {
1213                    header("Content-Disposition: filename=$file");
1214            } else {
1215                    header("Content-Disposition: attachment; filename=$file");
1216            }
1217            header("Content-Transfer-Encoding: binary");
1218            $fh = fopen($path, "r");
1219            fpassthru($fh);
1220    }
1221    
1222    
1223    //////////////////////////////////////////////////////////////////
1224    
1225    function chopsl($path) {
1226            if (substr($path,strlen($path)-1,1) == "/") $path=substr($path,0,strlen($path)-1);
1227            $path=str_replace("//","/",$path);
1228            return $path;
1229    }
1230    
1231    //////////////////////////////////////////////////////////////////
1232  // MAIN PROGRAM  // MAIN PROGRAM
1233  // ============  // ============
1234  // query parameters: capital letters  // query parameters: capital letters
# Line 1167  function DisplayChangeLog($day) { Line 1245  function DisplayChangeLog($day) {
1245          // creation if password not yet set.          // creation if password not yet set.
1246          if ($STYLE == "get") { CSS() ; exit ; }          if ($STYLE == "get") { CSS() ; exit ; }
1247    
1248          $htusers_file=dirname($SCRIPT_FILENAME)."/.htusers";          $fsScriptDir  = dirname($SCRIPT_FILENAME) ;    
1249          if (! file_exists($htusers_file)) {          // i.e. /home/httpd/html/docman
1250                  if (is_writeable(dirname($SCRIPT_FILENAME))) {  
1251                          $htusers=fopen($htusers_file,"a+");          // read user-defined configuration
1252                          fputs($htusers,"# Change owner of $htusers_file to root !!\n");          if (file_exists("$fsScriptDir/.docman.conf")) {
1253                          fputs($htusers,"demo:full name:[md5_hash|auth_*]:e-mail\n");                  include("$fsScriptDir/.docman.conf");
                         fclose($htusers);  
                         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!");  
                         exit;  
                 } else {  
                         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!");  
                         exit;  
                 }  
1254          }          }
1255          $htusers=fopen($htusers_file,"r");  
1256          while($user = fgetcsv($htusers,255,":")) {          // where do we get users from?
1257                  if ($user[0] == $GLOBALS["PHP_AUTH_USER"]) {          if (file_exists("$gblIncDir/$gblUsers.php")) {
1258                          $gblUserName=$user[1];                  include("$gblIncDir/$gblUsers.php");
1259                          $gblPw=$user[2];          } else {
1260                          if (substr($gblPw,0,5) == "auth_" && file_exists("$gblIncDir/$gblPw.php")) {                  Error("Configuration error","Can't find user handling module at <tt>$gblIncDir/$gblUsers.php</tt> ! Please fix <tt>$fsScriptDir/.docman.conf</tt>");
1261                                  require("$gblIncDir/$gblPw.php");          }
1262                                  if ($gblPw($user)) {  
1263                                          $gblPw=md5($PHP_AUTH_USER.$PHP_AUTH_PW);          // if no password, or empty password logout
1264                                  } else {          if (
1265                                          $gblPw="error".md5($PHP_AUTH_USER.$PHP_AUTH_PW);                  isset($PHP_AUTH_USER) && (
1266                                  }                          !isset($relogin) || (
1267                          }                                  isset($relogin) && $relogin != md5($PHP_AUTH_USER.$PHP_AUTH_PW)
1268                          $gblEmail=$user[3];                          )
1269                          continue ;                  ) && (
1270                  }                          $PHP_AUTH_PW == "" || !isset($PHP_AUTH_PW)
1271                    )
1272               ) {
1273                    StartHTML("Logout completed","Your login credentials has been erased") ;
1274                    EndHTML() ;
1275                    exit ;
1276          }          }
         fclose($htusers);  
1277    
1278          // authentication failure          // authentication failure
1279          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||          if ( md5($PHP_AUTH_USER.$PHP_AUTH_PW) != $gblPw ||
1280                  isset($relogin) && $gblPw == $relogin ) {                  isset($relogin) && $gblPw == $relogin) {
1281                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;                  header("WWW-authenticate: basic realm=\"$HTTP_HOST\"") ;
1282                  header("HTTP/1.0 401 Unauthorized") ;                  header("HTTP/1.0 401 Unauthorized") ;
1283                  NoEntry() ;                  NoEntry() ;
# Line 1230  function DisplayChangeLog($day) { Line 1305  function DisplayChangeLog($day) {
1305          $relScriptDir = dirname($SCRIPT_NAME) ;                  $relScriptDir = dirname($SCRIPT_NAME) ;        
1306          // i.e. /docman          // i.e. /docman
1307    
         $fsScriptDir  = dirname($SCRIPT_FILENAME) ;      
         // i.e. /home/httpd/html/docman  
   
1308          // start on server root          // start on server root
1309  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;  //      $gblFsRoot = substr($fsScriptDir,0, strlen($fsScriptDir)-strlen($relScriptDir)) ;
1310          // or on script root          // or on script root
# Line 1251  function DisplayChangeLog($day) { Line 1323  function DisplayChangeLog($day) {
1323    
1324          $FN=stripSlashes($FN);          $FN=stripSlashes($FN);
1325    
         if (file_exists("$fsScriptDir/.docman.conf")) {  
                 include("$fsScriptDir/.docman.conf");  
         }  
1326    
1327          switch ($POSTACTION) {          switch ($POSTACTION) {
1328          case "UPLOAD" :          case "UPLOAD" :
# Line 1432  function DisplayChangeLog($day) { Line 1501  function DisplayChangeLog($day) {
1501          // $A=Co : checkout file $D/$F          // $A=Co : checkout file $D/$F
1502          // $A=Ci : checkin file $D/$F          // $A=Ci : checkin file $D/$F
1503          // $A=V : view file (do nothing except log)          // $A=V : view file (do nothing except log)
1504            // $A=I : include file .$F.php from $gblFsRoot
1505          // default : display directory $D          // default : display directory $D
1506    
1507          switch ($A) {          switch ($A) {
# Line 1458  function DisplayChangeLog($day) { Line 1528  function DisplayChangeLog($day) {
1528          case "Co" :          case "Co" :
1529                  // checkout                  // checkout
1530                  Lock("$gblFsRoot/$relDir/$F");                  Lock("$gblFsRoot/$relDir/$F");
1531                  header("Content-Disposition: attachment; filename=$F" );                  Download("$gblFsRoot/$relDir/$F");
                 Header("Location: $webRoot".urlpath("$relDir/$F"));  
1532                  exit;                  exit;
1533          case "Ci" :          case "Ci" :
1534                  $F=stripSlashes($F);                  $F=stripSlashes($F);
# Line 1475  function DisplayChangeLog($day) { Line 1544  function DisplayChangeLog($day) {
1544          case "V" :          case "V" :
1545                  // view                  // view
1546                  LogIt("$gblFsRoot/$relDir/$F","viewed");                  LogIt("$gblFsRoot/$relDir/$F","viewed");
1547                  header("Content-Disposition: attachment; filename=$F" );                  if ($gblForceDownload) {
1548                  Header("Location: $webRoot".urlpath("$relDir/$F"));                          Download("$gblFsRoot/$relDir/$F");
1549                    } else {
1550                            header("Content-Disposition: attachment; filename=$F" );
1551                            Header("Location: $webRoot".urlpath("$relDir/$F"));
1552                    }
1553                  exit;                  exit;
1554          case "Ch" :          case "Ch" :
1555                  StartHTML("(File changes)","All changes chronologicaly...");                  StartHTML("(File changes)","All changes chronologicaly...");
# Line 1488  function DisplayChangeLog($day) { Line 1561  function DisplayChangeLog($day) {
1561                  DisplayChangeLog(1);                  DisplayChangeLog(1);
1562                  EndHTML() ;                  EndHTML() ;
1563                  exit;                  exit;
1564            case "I" :
1565                    $F=stripSlashes($F);
1566                    $inc_file="${gblFsRoot}/.${F}.php";
1567                    if (!isset($F) || $F == "" || !file_exists($inc_file)) Error("Fatal error $inc_file"); // can't find file to include
1568                    if (!is_readable($inc_file))
1569                            Error("Read access to include file denied",".${F}.php");
1570                    $text  = "Your include file should define \$text variable which holds this text and \$title variable which is page title";
1571                    $title = "You should define \$title variable with page title";
1572                    include($inc_file);
1573                    StartHTML($title, $text) ;
1574                    print "<p>".GifIcon(up)." Back to <a href=$GLOBALS[PHP_SELF]>front page</a>.</p>";
1575                    EndHTML() ;
1576                    exit ;
1577          }          }
1578    
1579          // default: display directory $relDir          // default: display directory $relDir

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.50

  ViewVC Help
Powered by ViewVC 1.1.26