Add first-run web setup and Compose without environment or secrets
This commit is contained in:
23
homegate.py
23
homegate.py
@@ -359,9 +359,11 @@ def export_handler(config_path):
|
||||
|
||||
def serve_export(config_path):
|
||||
load_config(config_path)
|
||||
# Compose requires an explicit private host IP; never publish on every host interface.
|
||||
bind_ip = private_address(os.environ.get("SSH_BIND_IP", ""))
|
||||
require(ipaddress.ip_address(bind_ip).version == 4, "SSH_BIND_IP must be a private IPv4 address")
|
||||
# The standalone deployment enforces LAN access through the configured subnets.
|
||||
bind_ip = "LAN (configured in the web panel)"
|
||||
if os.environ.get("HOMEGATE_MANAGED_UI") != "1":
|
||||
bind_ip = private_address(os.environ.get("SSH_BIND_IP", ""))
|
||||
require(ipaddress.ip_address(bind_ip).version == 4, "SSH_BIND_IP must be a private IPv4 address")
|
||||
with ThreadingHTTPServer(("0.0.0.0", 8080), export_handler(config_path)) as server:
|
||||
LOG.info("SSH export available through Docker binding %s; path /ssh-config", bind_ip)
|
||||
server.serve_forever()
|
||||
@@ -565,15 +567,22 @@ def secret(name):
|
||||
|
||||
def cycle(config, state, ca, registry):
|
||||
verify = os.environ.get("API_CA_BUNDLE") or True
|
||||
npm = NPM(os.environ.get("NPM_URL", ""), "NPM", verify)
|
||||
settings_file = os.environ.get("HOMEGATE_CONNECTIONS")
|
||||
settings = read_json(Path(settings_file)) if settings_file else None
|
||||
if settings is not None and settings.get("api_ca_pem"):
|
||||
ca_path = Path(settings_file).with_name("management-ca.pem")
|
||||
atomic(ca_path, settings["api_ca_pem"].encode(), 0o600)
|
||||
verify = str(ca_path)
|
||||
npm = NPM(settings["npm_url"] if settings is not None else os.environ.get("NPM_URL", ""), "NPM", verify)
|
||||
dns = None
|
||||
dns_error = False
|
||||
try:
|
||||
npm.login(os.environ.get("NPM_IDENTITY", ""), secret("NPM"))
|
||||
npm.login(settings["npm_identity"] if settings is not None else os.environ.get("NPM_IDENTITY", ""),
|
||||
settings["npm_password"] if settings is not None else secret("NPM"))
|
||||
if config["dns_mode"] == "pihole6":
|
||||
dns = PiHole(os.environ.get("PIHOLE_URL", ""), "PIHOLE", verify)
|
||||
dns = PiHole(settings["pihole_url"] if settings is not None else os.environ.get("PIHOLE_URL", ""), "PIHOLE", verify)
|
||||
try:
|
||||
dns.login(secret("PIHOLE"))
|
||||
dns.login(settings["pihole_password"] if settings is not None else secret("PIHOLE"))
|
||||
except (Error, OSError) as exc:
|
||||
LOG.error("Pi-hole login unavailable; continuing proxy maintenance: %s", exc)
|
||||
dns.close()
|
||||
|
||||
Reference in New Issue
Block a user