-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmauth-proxy
executable file
·40 lines (30 loc) · 1.29 KB
/
mauth-proxy
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
#!/usr/bin/env ruby
# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path('../lib', File.dirname(__FILE__))
require 'mauth/proxy'
require 'rack'
headers = []
headers_index = ARGV.find_index('--header')
while headers_index
headers << ARGV[headers_index + 1]
ARGV.delete_at(headers_index + 1)
ARGV.delete_at(headers_index)
headers_index = ARGV.find_index('--header')
end
authenticate_responses = !ARGV.delete('--no-authenticate')
browser_proxy = !ARGV.delete('--browser_proxy').nil?
target_uri = browser_proxy ? ARGV : ARGV.pop
if !target_uri || target_uri.empty?
abort("Usage: mauth-proxy [rack options] --browser_proxy [--no-authenticate] <target URI> <target URI> ...\n" \
'or: mauth-proxy [rack options] <target URI>')
end
rack_server_options = Rack::Server::Options.new.parse!(ARGV)
# for security, this rack server will only accept local connections, so override Host
# to 127.0.0.1 (from the default of 0.0.0.0)
#
# this means that the '-o' / '--host' option to Rack::Server::Options is ignored.
rack_server_options[:Host] = '127.0.0.1'
rack_server_options[:app] = MAuth::Proxy.new(target_uri, authenticate_responses: authenticate_responses,
browser_proxy: browser_proxy, headers: headers)
mauth_proxy_server = Rack::Server.new(rack_server_options)
mauth_proxy_server.start