|
|
@ -3,23 +3,60 @@ package com.jesuspinar.webserver; |
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.ui.Model; |
|
|
|
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
|
|
|
|
|
|
|
import java.net.*; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
|
|
|
@Controller |
|
|
|
public class Manager { |
|
|
|
@GetMapping({"/", "", "/index"}) |
|
|
|
public String welcome(Model model){ |
|
|
|
public String welcome(Model model) { |
|
|
|
loadTheme(model); |
|
|
|
model.addAttribute("mesage", "Hello"); |
|
|
|
return "index"; |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("/hour") |
|
|
|
public String hour(Model model){ |
|
|
|
@GetMapping("/time") |
|
|
|
public String hour(Model model) { |
|
|
|
loadTheme(model); |
|
|
|
return "time"; |
|
|
|
return "files/time"; |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("/whoami") |
|
|
|
public String test(Model model) throws MalformedURLException { |
|
|
|
loadTheme(model); |
|
|
|
|
|
|
|
InetAddress inetAddress = null; |
|
|
|
String hostnameCanonical = null; |
|
|
|
String hostname = null; |
|
|
|
byte[] address = null; |
|
|
|
|
|
|
|
String currentURL = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString(); |
|
|
|
URL requestURL = new URL(currentURL); |
|
|
|
|
|
|
|
try { |
|
|
|
inetAddress = InetAddress.getByName(InetAddress.getLocalHost().getHostName()); |
|
|
|
hostnameCanonical = inetAddress.getCanonicalHostName(); |
|
|
|
address = inetAddress.getAddress(); |
|
|
|
hostname = inetAddress.getHostName(); |
|
|
|
} catch (UnknownHostException e) { |
|
|
|
model.addAttribute("error", "UnknownHostException"); |
|
|
|
} |
|
|
|
//Data from the user |
|
|
|
model.addAttribute("inetAddress", inetAddress); |
|
|
|
model.addAttribute("hostname", hostname); |
|
|
|
model.addAttribute("hostnameCanonical", hostnameCanonical); |
|
|
|
model.addAttribute("address", address); |
|
|
|
//Data from the server |
|
|
|
model.addAttribute("url", currentURL); |
|
|
|
model.addAttribute("protocol", requestURL.getProtocol()); |
|
|
|
//ToDo: split host info in a class |
|
|
|
model.addAttribute("host", requestURL.getHost()); |
|
|
|
model.addAttribute("port", requestURL.getPort()); |
|
|
|
|
|
|
|
return "files/whoami"; |
|
|
|
} |
|
|
|
|
|
|
|
private void loadTheme(Model model) { |
|
|
@ -28,7 +65,7 @@ public class Manager { |
|
|
|
DateTimeFormatter hour = DateTimeFormatter.ofPattern("HH"); |
|
|
|
int h = Integer.parseInt(hour.format(LocalDateTime.now())); |
|
|
|
String bg = "light"; |
|
|
|
if (h >= 20 || h <= 7){ |
|
|
|
if (h >= 20 || h <= 7) { |
|
|
|
bg = "dark"; |
|
|
|
} |
|
|
|
model.addAttribute("background", bg); |
|
|
|