-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapplication.rb
More file actions
50 lines (42 loc) · 1023 Bytes
/
Copy pathapplication.rb
File metadata and controls
50 lines (42 loc) · 1023 Bytes
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
class Prophet < Merb::Controller
before :authenticate
before :ping, :exclude => [:no_god]
##
# Shows status and resource usage of all watches
##
def index
@watches = GOD.watches
display @watches
end
##
# Displays simple error is god connection is lost
##
def no_god
render "<h2 class='error'>Error: Could not connect to a God instance!</h2><h3>Perhaps the daemon died?</h3>"
end
##
# Handles control commands for services
##
def control(command, service)
return redirect(url(:root)) unless ACTIONS.include? command.to_s
GOD.control service, command.to_s
redirect url(:root)
end
protected
##
# Basic authentication for interface
##
def authenticate
basic_authentication("Prophet") do |username, password|
(password == PASSWORD) and (username == USERNAME)
end
end
##
# Ensures connection to god before interacting with the daemon
##
def ping
GOD.ping
rescue DRb::DRbConnError
throw :halt, redirect(url(:no_god))
end
end