Use configurable imagepath url

This allows images to be hosted externally, removing the need to do
image handling in vmmd.
This commit is contained in:
Tom Marshall 2021-04-22 08:44:43 -07:00
parent 720cebea0d
commit f212276a70
1 changed files with 3 additions and 19 deletions

22
vmmd
View File

@ -1391,7 +1391,7 @@ class HttpClientRequestHandler(http.server.BaseHTTPRequestHandler):
r += ' <table width="100%">\n'
r += ' <tr>\n'
r += ' <td width="33%">&nbsp;\n'
r += ' <td width="33%" align="center"><img src="/ui/vmm.jpg" alt="logo">\n'
r += " <td width=\"33%%\" align=\"center\"><img src=\"%s/logo.jpg\" alt=\"logo\">\n" % (config['ui.imagepath'])
if user:
r += " <td width=\"33%%\" align=\"right\" valign=\"top\">%s<br><a style=\"text-decoration:none\" href=\"/ui/logout\">logout</a>\n" % (user.fullname())
else:
@ -1464,21 +1464,6 @@ class HttpClientRequestHandler(http.server.BaseHTTPRequestHandler):
r += '</select>'
return r
def logo_image(self):
buf = b''
try:
f = open('/etc/vmm/logo.jpg', 'rb') # XXX: usr/lib/vmm or usr/share or ...
buf = f.read()
f.close()
except BaseException as e:
print("Failed to open image: %s" % (e))
pass
self.send_response(200)
self.send_header('Content-Type', 'image/jpeg')
self.send_header('Content-Length', len(buf))
self.end_headers()
self.wfile.write(buf)
def ui_login(self, user, args):
msg = None
if 'username' in args and 'password' in args:
@ -2157,9 +2142,6 @@ class HttpClientRequestHandler(http.server.BaseHTTPRequestHandler):
self._send_response(500, None, r)
def do_GET(self):
if self.path == '/ui/vmm.jpg':
self.logo_image()
return
self._handle_request()
def do_POST(self):
@ -2306,6 +2288,8 @@ config_defaults = {
'http.listen.address': '127.0.0.1',
'http.listen.port': 8080,
'ui.imagepath': 'https://www.nwwn.com/vmm/images',
'iso.storage.location': '/var/lib/vmm/isos',
'image.storage.location': '/var/lib/vmm/images',