From 9c7de15373b34397dca62f0f17f3395020424fe6 Mon Sep 17 00:00:00 2001 From: Michael Heimpold Date: Thu, 12 May 2022 21:34:25 +0200 Subject: [PATCH] Generate endpoint info on About page based on provided HTTP host header Showing all the interface addresses we're listening on is not helpful on the About page. However, we serve the About page, we already know that we are reaching the server using the given hostname in the corresponding HTTP header, so let's use it to construct the URLs. This takes also into account that the request/access already passed proxy server(s), uses DNS CNAMEs etc. Signed-off-by: Michael Heimpold --- .../controller/AboutSettingsController.java | 11 +++-- .../idsg/steve/web/dto/WebEndpointInfo.java | 47 +++++++++++++++++++ .../resources/webapp/WEB-INF/views/about.jsp | 4 +- 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/rwth/idsg/steve/web/dto/WebEndpointInfo.java diff --git a/src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java b/src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java index 5c9214e6b..9d31b84b8 100644 --- a/src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java +++ b/src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java @@ -23,7 +23,7 @@ import de.rwth.idsg.steve.repository.SettingsRepository; import de.rwth.idsg.steve.service.MailService; import de.rwth.idsg.steve.service.ReleaseCheckService; -import de.rwth.idsg.steve.web.dto.EndpointInfo; +import de.rwth.idsg.steve.web.dto.WebEndpointInfo; import de.rwth.idsg.steve.web.dto.SettingsForm; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import static de.rwth.idsg.steve.SteveConfiguration.CONFIG; @@ -66,14 +67,18 @@ public class AboutSettingsController { // ------------------------------------------------------------------------- @RequestMapping(value = ABOUT_PATH, method = RequestMethod.GET) - public String getAbout(Model model) { + public String getAbout(HttpServletRequest request, Model model) { + WebEndpointInfo info = new WebEndpointInfo(); + info.getOcppSoap().setUrlPrefix("http", request.getServerName()); + info.getOcppWebSocket().setUrlPrefix("ws", request.getServerName()); + model.addAttribute("version", CONFIG.getSteveVersion()); model.addAttribute("db", genericRepository.getDBVersion()); model.addAttribute("logFile", logController.getLogFilePath()); model.addAttribute("systemTime", DateTime.now()); model.addAttribute("systemTimeZone", DateTimeZone.getDefault()); model.addAttribute("releaseReport", releaseCheckService.check()); - model.addAttribute("endpointInfo", EndpointInfo.INSTANCE); + model.addAttribute("endpointInfo", info); return "about"; } diff --git a/src/main/java/de/rwth/idsg/steve/web/dto/WebEndpointInfo.java b/src/main/java/de/rwth/idsg/steve/web/dto/WebEndpointInfo.java new file mode 100644 index 000000000..7ffcbf58d --- /dev/null +++ b/src/main/java/de/rwth/idsg/steve/web/dto/WebEndpointInfo.java @@ -0,0 +1,47 @@ +/* + * SteVe - SteckdosenVerwaltung - https://github.com/RWTH-i5-IDSG/steve + * Copyright (C) 2013-2022 RWTH Aachen University - Information Systems - Intelligent Distributed Systems Group (IDSG). + * All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package de.rwth.idsg.steve.web.dto; + +import lombok.Getter; + +/** + * @author Michael Heimpold + */ +@Getter +public final class WebEndpointInfo { + private final ItemsWithInfo ocppSoap = new ItemsWithInfo("SOAP endpoint for OCPP", "/services/CentralSystemService"); + private final ItemsWithInfo ocppWebSocket = new ItemsWithInfo("WebSocket/JSON endpoint for OCPP", "/websocket/CentralSystemService/(chargeBoxId)"); + + @Getter + public static class ItemsWithInfo { + private final String info; + private final String path; + private String url; + + private ItemsWithInfo(String info, String path) { + this.info = info; + this.path = path; + this.url = ""; + } + + public synchronized void setUrlPrefix(String scheme, String serverName) { + this.url = scheme + "://" + serverName + path; + } + } +} diff --git a/src/main/resources/webapp/WEB-INF/views/about.jsp b/src/main/resources/webapp/WEB-INF/views/about.jsp index 7f4e3ede4..7bbf7c556 100644 --- a/src/main/resources/webapp/WEB-INF/views/about.jsp +++ b/src/main/resources/webapp/WEB-INF/views/about.jsp @@ -40,10 +40,10 @@ - + - +
${endpointInfo.ocppSoap.info}:${i}
${endpointInfo.ocppSoap.url}
${endpointInfo.ocppWebSocket.info}:${i}
${endpointInfo.ocppWebSocket.url}