Fix bug with fake redirects and bugged js loadings

This commit is contained in:
Ilya 2021-02-20 16:40:23 +03:00
parent b785901d3b
commit de49ecdd8c
4 changed files with 9 additions and 10 deletions

View File

@ -66,6 +66,6 @@ public class WebServer extends NanoHTTPD {
} }
} }
} }
return newFixedLengthResponse("Not Founded!"); return newFixedLengthResponse(Response.Status.NOT_FOUND,"text/plain","Not Founded!");
} }
} }

View File

@ -21,24 +21,23 @@ public class Worker implements IWebPage {
} }
Map<String, List<String>> decodedQueryParameters = WebUtils.decodeParams(session.getQueryParameterString()); Map<String, List<String>> decodedQueryParameters = WebUtils.decodeParams(session.getQueryParameterString());
if(!decodedQueryParameters.containsKey("user")) { if(!decodedQueryParameters.containsKey("user")) {
NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT,NanoHTTPD.MIME_PLAINTEXT,""); NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT_SEE_OTHER,NanoHTTPD.MIME_PLAINTEXT,"");
response.addHeader("Location","/auth/"); response.addHeader("Location","/auth/");
return response; return response;
} else { } else {
if(!decodedQueryParameters.containsKey("password")) { if(!decodedQueryParameters.containsKey("password")) {
NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT,NanoHTTPD.MIME_PLAINTEXT,""); NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT_SEE_OTHER,NanoHTTPD.MIME_PLAINTEXT,"");
response.addHeader("Location","/auth/"); response.addHeader("Location","/auth/");
return response; return response;
} else { } else {
UsersConfig usersConfig = new UsersConfig(); User user = UsersConfig.getUser(decodedQueryParameters.get("user").get(0));
User user = usersConfig.getUser(decodedQueryParameters.get("user").get(0));
if(user == null) { if(user == null) {
NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT,NanoHTTPD.MIME_PLAINTEXT,""); NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT_SEE_OTHER,NanoHTTPD.MIME_PLAINTEXT,"");
response.addHeader("Location", "/auth/"); response.addHeader("Location", "/auth/");
return response; return response;
} else { } else {
if (!user.password.equals(decodedQueryParameters.get("password").get(0))) { if (!user.password.equals(decodedQueryParameters.get("password").get(0))) {
NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT,NanoHTTPD.MIME_PLAINTEXT,""); NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT_SEE_OTHER,NanoHTTPD.MIME_PLAINTEXT,"");
response.addHeader("Location", "/auth/"); response.addHeader("Location", "/auth/");
return response; return response;
} else { } else {
@ -47,7 +46,7 @@ public class Worker implements IWebPage {
WebUtils.CookieHandler ch = new WebUtils.CookieHandler(session.getHeaders()); WebUtils.CookieHandler ch = new WebUtils.CookieHandler(session.getHeaders());
ch.set("session",token,1); ch.set("session",token,1);
WebStatic.sessions.put(token,user.user); WebStatic.sessions.put(token,user.user);
NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.TEMPORARY_REDIRECT,NanoHTTPD.MIME_PLAINTEXT,""); NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT_SEE_OTHER,NanoHTTPD.MIME_PLAINTEXT,"");
response.addHeader("Location", "/"); response.addHeader("Location", "/");
ch.unloadQueue(response); ch.unloadQueue(response);
config.getLogger().info(LoggerType.Web,user.user + " login!"); config.getLogger().info(LoggerType.Web,user.user + " login!");

View File

@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets;
public class Index implements IWebPage { public class Index implements IWebPage {
public NanoHTTPD.Response getPage(Config config, NanoHTTPD.IHTTPSession session) throws IOException { public NanoHTTPD.Response getPage(Config config, NanoHTTPD.IHTTPSession session) throws IOException {
if(!SessionUtils.checkAdmin(session)) { if(!SessionUtils.checkAdmin(session)) {
NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.TEMPORARY_REDIRECT, NanoHTTPD.MIME_PLAINTEXT, ""); NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT_SEE_OTHER, NanoHTTPD.MIME_PLAINTEXT, "");
response.addHeader("Location", "/"); response.addHeader("Location", "/");
return response; return response;
} }

View File

@ -14,7 +14,7 @@ public class Index implements IWebPage {
config.getLogger().info(LoggerType.Web,WebStatic.sessions.get(ch.read("session"))+ " has been logout!"); config.getLogger().info(LoggerType.Web,WebStatic.sessions.get(ch.read("session"))+ " has been logout!");
WebStatic.sessions.remove(ch.read("session")); WebStatic.sessions.remove(ch.read("session"));
ch.delete("session"); ch.delete("session");
NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT,NanoHTTPD.MIME_PLAINTEXT,""); NanoHTTPD.Response response = NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.REDIRECT_SEE_OTHER,NanoHTTPD.MIME_PLAINTEXT,"");
response.addHeader("Location", "/"); response.addHeader("Location", "/");
ch.unloadQueue(response); ch.unloadQueue(response);
return response; return response;