1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#!/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 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
puts '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >'
puts '<head>'
puts ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'
puts ' <meta http-equiv="refresh" content="0; url=' + "#{url}" + '">'
puts '</head>'
puts '<body></body>'
puts '</html>'
end
else
random = ""
1.upto(32) { random += (rand(26) + ?a).chr }
puts "Content-type: text/html"
puts
puts '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
puts '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >'
puts '<head>'
puts ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'
puts " <title>Disk usage : #{path}</title>"
puts ' <style type="text/css">'
puts ' <!--'
puts ' body {color:black;text-align:center;background:#FAFAFA;}'
puts ' table {margin:auto;width:780px;}'
puts ' table,td {border:0;}'
puts ' td {padding:4px;text-align:left;}'
puts ' td.size {text-align:right;}'
puts ' thead td {font-weight:bold;border-bottom:1px solid black;background:#EEE;}'
puts ' tbody td {background:#F0F0F0;}'
puts ' tbody tr.parentdir td {background:#E5D0D0;}'
puts ' tbody tr.evenrow td {background:#E4E4E4;}'
puts ' '
puts ' -->'
puts ' </style>'
puts '</head>'
puts '<body>'
puts ' <p><a href="' + "?path=#{path}&" + '">'
puts ' <img style="border:0" width="#{size}" height="#{size}" src="?cmd=img&r=' + "#{random}&path=#{path}" + '" ismap="ismap" alt="' + "#{path}" + '" />'
puts ' </a></p>'
if show_list then
# Array of files
content = ps.listcontent("#{path}")
if(content && content[0]) then
puts ' <table summary="File lists">'
puts ' <thead>'
puts ' <tr><td>Filename</td><td class="size">Size</td></tr>'
puts ' </thead>'
puts ' <tbody>'
puts ' <tr class="parentdir"><td>' + content[0][:path].to_s + '</td><td class="size">' + content[0][:humansize].to_s + '</td></tr>'
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 ' <tr class="evenrow">'
else
print ' <tr>'
end
puts '<td><a href="?path='+ CGI.escape(f[:path].to_s) +'">' + f[:path].to_s + '</a></td><td class="size">' + f[:humansize].to_s + '</td></tr>'
linenum += 1
end
end
puts ' </tbody>'
puts ' </table>'
end
end
puts '</body>'
puts '</html>'
end
#
# End
#
|