package ru.redguy.webinfomod.pages.cp; import fi.iki.elonen.NanoHTTPD; import org.apache.commons.io.IOUtils; import ru.redguy.webinfomod.*; import ru.redguy.webinfomod.utils.PlaceholdersUtils; import ru.redguy.webinfomod.utils.SessionUtils; import java.io.IOException; import java.nio.charset.StandardCharsets; @WebPage(url = "/cp") public class Index implements IWebPage { public NanoHTTPD.Response getPage(Config config, NanoHTTPD.IHTTPSession session) throws IOException { if(!SessionUtils.checkAdmin(session)) { NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT_SEE_OTHER, NanoHTTPD.MIME_PLAINTEXT, ""); response.addHeader("Location", "/"); return response; } String path = "/resources/web/cp/index.html"; String page = IOUtils.toString(WebServer.class.getResourceAsStream(path), StandardCharsets.UTF_8); return NanoHTTPD.newFixedLengthResponse(new PlaceholdersUtils(session).work(page)); } }