Skip to content

Commit

Permalink
modules.admin: Added option to handle a second webinterface (admin gui)
Browse files Browse the repository at this point in the history
  • Loading branch information
msinn committed May 30, 2024
1 parent 7afce66 commit 6573020
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion modules/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@


suburl = 'admin'
suburl2 = 'admin2'


class Admin(Module):
version = '1.8.1'
version = '1.8.2'
longname = 'Admin module for SmartHomeNG'
_port = 0

Expand Down Expand Up @@ -119,11 +120,15 @@ def __init__(self, sh, testparam=''):
mysuburl = ''
if suburl != '':
mysuburl = '/' + suburl
mysuburl2 = ''
if suburl2 != '':
mysuburl2 = '/' + suburl2
ip = Utils.get_local_ipv4_address()
self._port = self.mod_http._port
# self.logger.warning('port = {}'.format(self._port))
self.shng_url_root = 'http://' + ip + ':' + str(self._port) # for links mto plugin webinterfaces
self.url_root = self.shng_url_root + mysuburl
self.url_root2 = self.shng_url_root + mysuburl2
self.api_url_root = self.shng_url_root + 'api'
self.api2_url_root = self.shng_url_root + 'api2'

Expand All @@ -136,6 +141,7 @@ def start(self):
self.logger.dbghigh(self.translate("Methode '{method}' aufgerufen", {'method': 'start()'}))

self.webif_dir = os.path.dirname(os.path.abspath(__file__)) + '/webif'
self.webif2_dir = os.path.dirname(os.path.abspath(__file__)) + '/webif2'

self.logger.info("Module '{}': webif_dir = webif_dir = {}".format(self._shortname, self.webif_dir))
# config for Angular app (special: error page)
Expand All @@ -156,6 +162,24 @@ def start(self):
# 'tools.auth_basic.realm': 'shng_admin_webif',
}
}
# config for Angular app (special: error page)
config2 = {
'/': {
'tools.staticdir.root': self.webif2_dir,
'tools.staticdir.on': True,
'tools.staticdir.dir': 'static',
'tools.staticdir.index': 'index.html',
'tools.chaching.on': False,
'tools.caching.force': False,
'tools.caching.delay': 6,
'tools.expires.on': True,
'tools.expires.secs': 6,
'error_page.404': self.webif2_dir + '/static/index.html',
# 'error_page.404': self.error_page,
# 'tools.auth_basic.on': False,
# 'tools.auth_basic.realm': 'shng_admin_webif',
}
}
# API config (special: request.dispatch)
config_api = {
'/': {
Expand Down Expand Up @@ -205,6 +229,7 @@ def start(self):
"""

# Register the web interface as a cherrypy app
self.logger.warning(f"register_webif: {self.webif_dir=}, {self.shng_url_root=}, {self.url_root=} - {suburl=}")
self.mod_http.register_webif(WebInterface(self.webif_dir, self, self.shng_url_root, self.url_root),
suburl,
config,
Expand All @@ -214,6 +239,17 @@ def start(self):
use_global_basic_auth=False,
useprefix=False)

# Register the alternate web interface as a cherrypy app
self.logger.warning(f"register_webif: {self.webif2_dir=}, {self.shng_url_root=}, {self.url_root2=} - {suburl2=}")
self.mod_http.register_webif(WebInterface(self.webif2_dir, self, self.shng_url_root, self.url_root2),
suburl2,
config2,
'admin2', '',
description='kommende Administrationsoberfläche für SmartHomeNG',
webifname='',
use_global_basic_auth=False,
useprefix=False)

# Register the web interface as a cherrypy app
self.mod_http.register_webif(WebApi(self.webif_dir, self, self.shng_url_root, self.api_url_root),
'api',
Expand Down
2 changes: 1 addition & 1 deletion modules/admin/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module:
# Global module attributes
classname: Admin
version: 1.8.1
version: 1.8.2
sh_minversion: 1.7.2c
# sh_maxversion: 1.3 # maximum shNG version to use this plugin (leave empty if latest)
description:
Expand Down

0 comments on commit 6573020

Please sign in to comment.