#!/usr/bin/ruby # vi: ts=4 sw=4 require 'philesight' require 'cgi' # Config variables db = "./ps.db" default_path = "/" size = 800 show_list = true use_gradients = true # Get parameters from environment and CGI. ISMAP image maps do not return a # proper CGI parameter, but only the coordinates appended after a question # mark. If this is found in the QUERY_STRING, assume the 'find' command cgi = CGI.new; qs = ENV["QUERY_STRING"] cmd = cgi.params['cmd'][0] path = cgi.params['path'][0] || default_path if(qs && qs =~ /\?(\d+,\d+)/ ) then find_pos = $1 cmd = 'find' end ps = Philesight.new(4, size, use_gradients) ps.db_open(db) # Perform action depending on 'cmd' parameter case cmd when "img" puts "Content-type: image/png" puts $stdout.flush ps.draw(path, "-") when "find" if(find_pos =~ /(\d+),(\d+)/) then x, y = $1.to_i, $2.to_i url = "?path=%s" % ps.find(path, x, y) puts "Content-type: text/html" puts puts '' puts '' puts '' puts ' ' puts ' ' puts '' puts '' puts '' end else random = "" 1.upto(32) { random += (rand(26) + ?a).chr } puts "Content-type: text/html" puts puts '' puts '' puts '' puts ' ' puts " Disk usage : #{path}" puts ' ' puts '' puts '' puts '

' puts ' ' + ' puts '

' if show_list then # Array of files content = ps.listcontent("#{path}") if(content && content[0]) then puts ' ' puts ' ' puts ' ' puts ' ' puts ' ' puts ' ' if(content[1].size > 0) then linenum = 0 content[1] = content[1].sort_by { |f| - f[:size] } content[1].each do |f| if(linenum%2 == 0) then print ' ' else print ' ' end puts '' linenum += 1 end end puts ' ' puts '
FilenameSize
' + content[0][:path].to_s + '' + content[0][:humansize].to_s + '
' + f[:path].to_s + '' + f[:humansize].to_s + '
' end end puts '' puts '' end # # End #