Skip to content

Introduce base_path for web interface #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
- Files included via the `[include]` section are read in sorted order. In
past versions, the order was undefined. Patch by Ionel Cristian Mărieș.

- Added ``base_path`` option in the `[inet_http_server]` section. This
allows to put the web interface behind a reverse proxy (i.e. web server).
The default value is ``/``.

- Fixed a bug introduced in 3.1.0 where ``supervisord`` could crash when
attempting to display a resource limit error.

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ Contributors
- Márk Sági-Kazár, 2013-12-16

- Gülşah Köse, 2014-07-17

- Seyeong Jeong, 2015-03-19
2 changes: 0 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@

- Option to automatically refresh the status page (issue #73).

- Better support for use with proxy servers (issue #29)

- Expat error on Jens' system running slapd as root after reload.

- Command-line arg tests.
Expand Down
12 changes: 12 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ configuration values are as follows.

*Introduced*: 3.0

``base_path``

Specify the base path for the web interface. For example,
``base_path=/supervisor/`` yields the web interface accessible at
``http://localhost:4567/supervisor/``.

*Default*: ``/``

*Required*: No.

*Introduced*: 4.0

``[inet_http_server]`` Section Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
12 changes: 10 additions & 2 deletions supervisor/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ def found_terminator (self):
command, uri, version = http_server.crack_request (request)
header = http_server.join_headers (lines[1:])

# strip the ``base_path`` so that the handlers don't need to know
# about the ``base_path``.
if uri.startswith(self.server.base_path):
uri = '/' + uri[len(self.server.base_path):]

# unquote path if necessary (thanks to Skip Montanaro for pointing
# out that we must unquote in piecemeal fashion).
rpath, rquery = http_server.splitquery(uri)
Expand Down Expand Up @@ -522,12 +527,13 @@ def log_info(self, message, type='info'):
class supervisor_af_inet_http_server(supervisor_http_server):
""" AF_INET version of supervisor HTTP server """

def __init__(self, ip, port, logger_object):
def __init__(self, ip, port, logger_object, base_path='/'):
self.ip = ip
self.port = port
sock = text_socket.text_socket(socket.AF_INET, socket.SOCK_STREAM)
self.prebind(sock, logger_object)
self.bind((ip, port))
self.base_path = base_path

if not ip:
self.log_info('Computing default hostname', 'warning')
Expand Down Expand Up @@ -799,8 +805,10 @@ def log(self, msg):

if family == socket.AF_INET:
host, port = config['host'], config['port']
base_path = config.get('base_path', '/')
hs = supervisor_af_inet_http_server(host, port,
logger_object=wrapper)
logger_object=wrapper,
base_path=base_path)
elif family == socket.AF_UNIX:
socketname = config['file']
sockchmod = config['chmod']
Expand Down
9 changes: 9 additions & 0 deletions supervisor/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,15 @@ def server_configs_from_parser(self, parser):
config['host'] = host
config['port'] = port
config['section'] = section

# sanitize base_path
base_path = get(section, 'base_path', '/')
if not base_path.endswith('/'):
base_path += '/'
if not base_path.startswith('/'):
base_path = '/' + base_path
config['base_path'] = base_path

configs.append(config)

unix_serverdefs = self._parse_servernames(parser, 'unix_http_server')
Expand Down
1 change: 1 addition & 0 deletions supervisor/skel/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ file=/tmp/supervisor.sock ; (the path to the socket file)
;port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
;base_path=/supervisor/ ; (default is /)

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
Expand Down
1 change: 1 addition & 0 deletions supervisor/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ def log(self, category, msg):
class DummyMedusaServer:
def __init__(self):
self.logger = DummyMedusaServerLogger()
self.base_path = '/'

class DummyMedusaChannel:
def __init__(self):
Expand Down
1 change: 1 addition & 0 deletions supervisor/ui/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title>Supervisor Status</title>
<link href="stylesheets/supervisor.css" rel="stylesheet" type="text/css" />
<link href="images/icon.png" rel="icon" type="image/png" />
<base meld:id="base_path" href="/" />
</head>
<body>
<div id="wrapper">
Expand Down
13 changes: 7 additions & 6 deletions supervisor/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def __call__(self):
response['body'] = as_string(body)
return response

@property
def base_path(self):
return self.context.request.channel.server.base_path

def render(self):
pass

Expand Down Expand Up @@ -429,9 +433,7 @@ def render(self):
if message is NOT_DONE_YET:
return NOT_DONE_YET
if message is not None:
server_url = form['SERVER_URL']
location = server_url + '?message=%s' % urllib.quote(
message)
location = '%s?message=%s' % (self.base_path, urllib.quote(message))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine but it should be noted that this PR quietly removed SERVER_URL from the redirect.

response['headers']['Location'] = location

supervisord = self.context.supervisord
Expand Down Expand Up @@ -511,6 +513,7 @@ def render(self):
root.findmeld('supervisor_version').content(VERSION)
copyright_year = str(datetime.date.today().year)
root.findmeld('copyright_date').content(copyright_year)
root.findmeld('base_path').attrib['href'] = self.base_path

return as_string(root.write_xhtmlstring())

Expand Down Expand Up @@ -556,9 +559,7 @@ def match(self, request):
if not path:
path = 'index.html'

for viewname in VIEWS.keys():
if viewname == path:
return True
return path in VIEWS.keys()

def handle_request(self, request):
if request.command == 'POST':
Expand Down