-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
110 lines (85 loc) · 2.1 KB
/
main.rb
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
%w( rubygems date sinatra/base haml ).each { |f| require f }
class ZFS_web < Sinatra::Base
configure do
set :views, File.join(File.dirname(__FILE__), 'views')
set :run, false
set :env, ENV['RACK_ENV']
end
error do
e = request.env['sinatra.error']
puts e.to_s
puts e.backtrace.join("\n")
"Application error"
end
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib')
require 'zpool'
require 'zfs'
helpers do
def admin?
request.cookies["test"] == '51d6d976913ace58'
end
def auth
stop [ 401, 'Not authorized' ] unless admin?
end
end
#layout 'default'
### Public
get '/' do
zfs = ZFS.list
haml :index, :locals => { :zfs => zfs }, :layout => :default
end
get '/volumes' do
zfs = ZFS.list :volume
haml :vols, :locals => { :zfs => zfs}, :layout => :default
end
get '/snapshots' do
zfs = ZFS.list :snapshot
haml :snapshots, :locals => { :zfs => zfs}, :layout => :default
end
get '/props/*' do
zf = params['splat'][0]
zp = ZFS.prop(zf)
haml :props, :locals => { :zprops => zp[zf]}, :layout =>:default
end
get '/snap/*' do
zf = params['splat'][0]
ZFS.snap(zf)
redirect '/snapshots'
end
get '/clone/*' do
sn = params['splat'][0]
haml :clone, :locals => { :snap => sn}, :layout => :default
end
post '/clone/*' do
puts sn = params['splat'][0]
puts newname = params[:clone]
ZFS.clone(sn, sn.split(/\/|@/)[0] + "/" + newname)
redirect '/'
end
get '/destroy/*' do
ZFS.destroy(params['splat'][0])
redirect '/snapshots'
end
get '/rollback/*' do
ZFS.rollback(params['splat'][0])
redirect '/snapshots'
end
### Admin
get '/auth' do
haml :auth
end
post '/auth' do
response.set_cookie("test", "51d6d976913ace58") if params[:password] == "test"
redirect '/'
end
get '/posts/new' do
auth
haml :edit, :locals => { :post => Post.new, :url => '/posts' }
end
post '/posts' do
auth
post = Post.new :title => params[:title], :tags => params[:tags], :body => params[:body], :created_at => Time.now, :slug => Post.make_slug(params[:title])
post.save
redirect post.url
end
end