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());
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/");
return response;
} else {
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/");
return response;
} 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) {
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/");
return response;
} else {
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/");
return response;
} else {
@ -47,7 +46,7 @@ public class Worker implements IWebPage {
WebUtils.CookieHandler ch = new WebUtils.CookieHandler(session.getHeaders());
ch.set("session",token,1);
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", "/");
ch.unloadQueue(response);
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 NanoHTTPD.Response getPage(Config config, NanoHTTPD.IHTTPSession session) throws IOException {
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", "/");
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!");
WebStatic.sessions.remove(ch.read("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", "/");
ch.unloadQueue(response);
return response;