-
Notifications
You must be signed in to change notification settings - Fork 2
/
postfix_admin.rb
48 lines (37 loc) · 1.22 KB
/
postfix_admin.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
require 'sinatra'
require 'sinatra/r18n'
require 'json'
require 'yaml'
class PostfixAdmin < Sinatra::Application
enable :sessions
configure do
config = YAML.load_file('conf/config.yml')
set :database_host => config['database']['host']
set :database_name => config['database']['name']
set :database_user => config['database']['user']
set :database_password => config['database']['password']
set :admin_name => config['auth']['username']
set :admin_password => config['auth']['password']
end
helpers do
include Rack::Utils
alias_method :h, :escape_html
def protected!
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="Testing HTTP Auth")
throw(:halt, [401, "Not authorized\n"])
end
end
def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == [settings.admin_name, settings.admin_password]
end
end
before do
session[:locale] = params[:locale] if params[:locale]
protected! unless request.path_info == "/"
end
end
require_relative 'app/models/init'
#require_relative 'helpers/init'
require_relative 'app/routes/init'