Skip to content

Commit

Permalink
Generate index.html on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Zellner committed Jul 14, 2021
1 parent e3d6e3b commit 2018aec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ out/
### Prevent from check-in!!! ###
*.jar
!gradle-wrapper.jar
/ffw/
/ffw/
/screenshots/index.html
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ FROM adoptopenjdk:16-jre-hotspot-focal
LABEL maintainer="FFW Baudenbach <webmaster@ffw-baudenbach.de>"
EXPOSE 8080
RUN mkdir -p /maps
COPY index.html /maps/index.html
WORKDIR application
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
Expand Down
3 changes: 0 additions & 3 deletions index.html

This file was deleted.

30 changes: 30 additions & 0 deletions src/main/java/com/fe2/configuration/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
Expand Down Expand Up @@ -46,6 +50,32 @@ public class Configuration implements HealthIndicator {
@Value("#{'${wk.customIcons:}'.split(';')}")
private List<String> wk_customIcons; // Optional

/**
* Create index.html file.
* This avoids directory listing if the directory is exposed via webserver.
* In addition it is used by FE2_Monitoring to check if maps can be reached.
*/
@PostConstruct
public void postConstruct() {

if (!isImageStoringEnabled()) {
return;
}

try {
File f = Paths.get(getOutputFolder(), "index.html").toFile();
f.createNewFile();

String html = "<!doctype html><title>Directory listing not allowed</title>Directory listing not allowed.";

try(BufferedWriter writer = new BufferedWriter(new FileWriter(f))) {
writer.write(html);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}

public String getGcpMapsApiKey() {
return gcp_maps_apiKey;
Expand Down

0 comments on commit 2018aec

Please sign in to comment.