package ru.redguy.webinfomod.pages; import fi.iki.elonen.NanoHTTPD; import org.apache.commons.io.IOUtils; import ru.redguy.webinfomod.*; import ru.redguy.webinfomod.langs.LangFile; import ru.redguy.webinfomod.langs.enums.Links; import ru.redguy.webinfomod.langs.enums.RootCategories; import ru.redguy.webinfomod.utils.WebUtils; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @WebPage(url = "/") public class Index implements IWebPage { public NanoHTTPD.Response getPage(Config config, LangFile langFile, NanoHTTPD.IHTTPSession session) throws IOException { String path = "/resources/web/pages/Index.html"; String page = IOUtils.toString(WebServer.class.getResourceAsStream(path), StandardCharsets.UTF_8); WebUtils.CookieHandler ch = new WebUtils.CookieHandler(session.getHeaders()); if(ch.read("session") == null) { page = page.replace("",""+langFile.getCategory(RootCategories.Links).getString(Links.login)+""); } else { page = page.replace("",""+langFile.getCategory(RootCategories.Links).getString(Links.logout)+"
" + ""+langFile.getCategory(RootCategories.Links).getString(Links.controlPanel)+""); } return NanoHTTPD.newFixedLengthResponse(page); } }