-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
81 lines (67 loc) · 1.87 KB
/
app.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
require "sinatra"
require "yaml"
require_relative "models/module"
require_relative "models/backup"
require_relative "models/remote_access"
Tilt.register(Tilt::ERBTemplate, "html.erb")
use Rack::Auth::Basic, "Protected Area" do |username, password|
config = load_config("auth")
username == config["username"] && password == config["password"]
end
# Main app and routes.
configure :production do
set :clean_trace, true
end
configure :development do
end
helpers do
include Rack::Utils
alias_method :h, :escape_html
end
before do
# We never want to cache any of our pages.
expires(0, :no_store, :no_cache, :must_revalidate)
end
get "/panel" do
@title = "Welcome"
erb(:main)
end
get "/panel/backup" do
@config = load_config("backup")
@title = "Backup"
@backup = Backup.new(@config)
erb(:backup)
end
post "/panel/backup/run" do
Process.fork do
settings.running_server = nil # Don't terminate web server when process finishes.
Backup.new(load_config("backup")).run
end
end
post "/panel/backup/reset" do
Backup.new(load_config("backup")).reset
end
get "/panel/remote" do
@config = load_config("remote")
@title = "Remote Access"
@remote = RemoteAccess.new(@config)
erb(:remote)
end
post "/panel/remote/start" do
Process.fork do
settings.running_server = nil # Don't terminate web server when process finishes.
RemoteAccess.new(load_config("remote")).start(params["mode"])
end
sleep(1) # Allow enough time for 'starting' status to be written.
end
post "/panel/remote/close" do
RemoteAccess.new(load_config("remote")).close
redirect("/panel/remote")
end
def load_config(key)
config = YAML.safe_load(File.read(File.join(settings.root, "config.yml")))
raise "#{key} config missing" unless config.is_a?(Hash) && config.key?(key)
config[key]["app_root"] = settings.root
config[key]["tmp_dir"] = File.join(settings.root, "tmp")
config[key]
end