<% require 'cgi' $cgi = CGI.new('html4Tr') # New CGI object charset = 'iso-8859-1' print $cgi.header("type"=>"text/html; charset=#{charset}") $dir = CGI.unescape( ENV[ 'REQUEST_URI' ].sub( /[?].*$/, '' ) ) $dir.sub!( /[\/][\/]*[^\/]*$/, '' ) $root = ENV[ 'DOCUMENT_ROOT' ].dup $root << $dir Dir.chdir( $root.untaint ) file = 'HEADER.html' if File.exist?( file ) print File.read( file ) else dir = 'Index of ' dir << $dir print ' ' print dir print '

' print dir print '

' end def bytes2text( bytes ) nbytes = bytes if ( nbytes < 1000 ) return sprintf( "%db", nbytes ) end nbytes = ( nbytes + 512 ) / 1024 if ( nbytes < 1000 ) return sprintf( "%dk", nbytes ) end if ( nbytes < 10000 ) return sprintf( "%.1fM", ( nbytes.to_f / 1024) ) end nbytes = ( nbytes + 512 ) / 1024 if ( nbytes < 1000 ) return sprintf( "%dM", nbytes ) end if ( nbytes < 10000 ) return sprintf( "%.1fG", ( nbytes.to_f / 1024) ) end nbytes = ( nbytes + 512 ) / 1024 if ( nbytes < 1000 ) return sprintf( "%dG", nbytes ) end if ( nbytes < 10000 ) return sprintf( "%.1fT", ( nbytes.to_f / 1024 ) ) end nbytes = ( nbytes + 512 ) / 1024 if ( nbytes < 1000 ) return sprintf( "%dT", nbytes ) end return sprintf( "%dE", nbytes ) end $suppresslastmodified = false ignore = [ '.' , 'CVS', 'HEADER.html', 'README.html' ] desc = Array.new check = '.htaccess' config = Array.new config.push( check.dup ) file = $dir.dup while file != '' file.sub!( /\/[^\/]*$/, '' ) check = "../" + check config.push( check.dup ) end config.reverse! # p config config.each do |file| if File.exist?( file ) read = File.read( file ) read.split( "\n" ).each do |line| case line when nil, '' next when /^IndexIgnore/ ( dummy, text, rest ) = line.split( '"', 3 ) ignore.push( text ) when /^AddDescription/ ( dummy, text, pattern ) = line.split( '"', 3 ) desc.push( [ pattern[ 1 .. -1 ], text ] ) when /^IndexOptions/ line.split( ' ' ).each do |word| case word when '+SuppressLastModified' $suppresslastmodified = true end end end end end end show1 = Array.new show2 = Array.new show3 = Array.new max = 0 all = Dir.entries(".") all.each do |file| if ignore.include?( file ) next end case file when /^[.][a-zA-Z0-9]/ next end comment = '' desc.each { |check| ( pattern, text ) = check if File.fnmatch?( pattern, file ) comment = text break end } file.untaint isdir = 0 stat = File.stat( file ) if stat.directory? file << '/' isdir = -1 if file == '../' show1.push( [ file, isdir, stat.mtime, stat.size, comment ] ) else show2.push( [ file, isdir, stat.mtime, stat.size, comment ] ) end else show3.push( [ file, isdir, stat.mtime, stat.size, comment ] ) end if file.size > max max = file.size end end def print_navi( key, val, text ) print '' print text print '' end def print_both_nvai( key, text ) case $cgi.params[ key ][0] when 'A' print_navi( key, 'D', text ) else print_navi( key, 'A', text ) end end puts '
' puts '' puts '' puts '' print '' print '' if not $suppresslastmodified print '' end print '' print '' puts '' puts '' print '' puts '' puts '' is_sorted = false case $cgi.params['D'][0] when 'A' show2 = show2.sort_by { |x| [x[4]] } show3 = show3.sort_by { |x| [x[4]] } is_sorted = true when 'D' show2 = show2.sort_by { |x| [x[4]] } show2.reverse! show3 = show3.sort_by { |x| [x[4]] } show3.reverse! is_sorted = true end if not $suppresslastmodified case $cgi.params['M'][0] when 'A' show2 = show2.sort_by { |x| [x[2]] } show3 = show3.sort_by { |x| [x[2]] } is_sorted = true when 'D' show2 = show2.sort_by { |x| [x[2]] } show2.reverse! show3 = show3.sort_by { |x| [x[2]] } show3.reverse! is_sorted = true end end case $cgi.params['S'][0] when 'A' show2 = show2.sort_by { |x| [x[0]] } show3 = show3.sort_by { |x| [x[3]] } is_sorted = true when 'D' show2 = show2.sort_by { |x| [x[0]] } show3 = show3.sort_by { |x| [x[3]] } show3.reverse! is_sorted = true end case $cgi.params['N'][0] when 'A' show2 = show2.sort_by { |x| [x[0]] } show3 = show3.sort_by { |x| [x[0]] } is_sorted = true when 'D' show2 = show2.sort_by { |x| [x[0]] } show2.reverse! show3 = show3.sort_by { |x| [x[0]] } show3.reverse! is_sorted = true end if not is_sorted show2 = show2.sort_by { |x| [x[0]] } show3 = show3.sort_by { |x| [x[0]] } end show = show1 | show2 | show3 puts '' show.each do |entry| puts '' ( file, isdir, mtime, bytes, comment ) = entry text = file if isdir != 0 alt = '[DIR]' case file when '../' file = $dir.sub( /\/$/, '' ) file.sub!( /\/[^\/]*$/, '' ) file << "/" icon = 'back' text = 'Parent Directory' else icon = 'folder' end size = '-' else icon = 'text' alt = '[TXT]' case file when /[.]gz$/, /[.]zip$/ icon = 'compressed' alt = '[ ]' when /[.]ico$/ icon = 'image2' alt = '[IMG]' end size = bytes2text( bytes ) end print '' print '' if not $suppresslastmodified print '' end print '' print '' puts '' end puts '' puts '
' print '     ' puts '' print_both_nvai( 'N', 'Name' ) puts '' print_both_nvai( 'M', 'Last modified' ) puts '' print_both_nvai( 'S', 'Size' ) puts '' print_both_nvai( 'D', 'Description' ) puts '
 ' puts '
' print ''
  print alt
  print '' print '' print '' print text print '' print '' print mtime.strftime( "%d-%b-%Y %H:%M" ) print '' print size print '' print comment print '
' puts '
' file = 'README.html' if File.exist?( file ) print File.read( file ) else print '

' msg = ENV[ 'SERVER_SIGNATURE' ] if msg.nil? msg = '
' msg << ENV[ 'SERVER_SOFTWARE' ] msg << " Server at " msg << ENV[ 'SERVER_NAME' ] msg << " Port " msg << ENV[ 'SERVER_PORT' ] msg << '
' end print msg print ' ' end %>