3 WIZARD_ROOT = File.dirname(__FILE__)
4 RAILS_ROOT = Pathname(WIZARD_ROOT + "/../")
5 ENV["BUNDLE_GEMFILE"] = (RAILS_ROOT + "Gemfile").to_s
7 $LOAD_PATH << WIZARD_ROOT + "/lib"
8 $LOAD_PATH << (RAILS_ROOT + "lib").to_s
9 $LOAD_PATH << (RAILS_ROOT + "app").to_s
12 Bundler.setup(:default, :ldap_wizard)
18 require "ldap_configuration_presenter"
20 require "gitorious/configuration_reader"
21 require "auth_config_loader"
24 require "sinatra/reloader"
26 require "gitorious/authentication"
27 require "gitorious/authentication/ldap_configurator"
28 require "gitorious/authentication/ldap_authentication"
29 require "makeup/markup"
35 class ConfigurationError < StandardError
39 readme_file = Pathname(WIZARD_ROOT + "/README.md")
40 @readme = Makeup::Markup.new.render("README.md", readme_file.read)
46 @configurator = AuthConfigLoader.load_auth_file
47 @credentials = Credentials.new
49 rescue ConfigurationError => e
50 render_error e.message
55 params["bind_user"] = {"username" => params[:bind_username], "password" => params[:bind_password]}
56 configuration = Gitorious::Authentication::LDAPConfigurator.new(params)
57 @configurator = LdapConfigurationPresenter.new(configuration)
58 @credentials = Credentials.from_params(params)
59 ldap_tester = LdapTester.new(configuration, @credentials)
60 @test_results = ldap_tester.execute
64 # Curl'able interface. Do a HTTP POST with username and password parameters for a quick sanity check
66 configurator = AuthConfigLoader.load_auth_file.config
67 credentials = Credentials.from_params(params)
68 tester = LdapTester.new(configurator, credentials)
71 body "Authentication succeeded"
74 body "Authentication failed"
79 def field(obj, name, description, help_text=nil, options=nil)
80 value = obj.public_send(name.to_sym)
81 result = "<div class=\"control-group\">"
82 result << "<label class=\"control-label\">#{description}</label>\n"
83 result << "<div class=\"controls\">"
85 result << select_field(name, value.to_s, options)
87 result << text_field(name, value)
90 result << "<span class=\"help-block\">#{help_text}</span>" if help_text
95 def text_field(name, value)
96 field_type = (name == :password) ? "password" : "text"
97 "<input type =\"#{field_type}\" name=\"#{name}\" value=\"#{value}\">"
100 def select_field(name, value, options)
101 result = "<select name=\"#{name}\">"
102 options.each do |option|
103 selected = (option == value) ? " selected" : ""
104 result << "<option value=\"#{option}\" #{selected}>#{option}</option>"
106 result << "</select>"
114 def render_error(message)