bugfixing

This commit is contained in:
Niklas 2017-07-03 23:12:00 +02:00
parent 58482bf285
commit e457a6c267
3 changed files with 19 additions and 11 deletions

View File

@ -50,6 +50,7 @@ public class Config extends JSONObject {
JSONObject uploadserver = new JSONObject();
uploadserver.put("port", 8888);
uploadserver.put("timeout", 5);
uploadserver.put("bind", "0.0.0.0");
this.put("uploadserver", uploadserver);

View File

@ -53,7 +53,7 @@ public class UploadServer {
this.clientIP = socketOfServer.getInetAddress().toString().substring(1);
this.client = "client#" + clientNumber + "@" + clientIP + ":" + socketOfServer.getPort();
try {
this.socketOfServer.setSoTimeout(2000);
this.socketOfServer.setSoTimeout(Termbin.getConfig().getUploadServerConfig().getInt("timeout") * 1000);
} catch (SocketException e) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, e);
}
@ -91,19 +91,27 @@ public class UploadServer {
return;
}
}
} catch (SocketTimeoutException e) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "closed " + client + " with error invalid data");
os.write("Invalid data");
os.newLine();
os.flush();
socketOfServer.close();
return;
} catch (SocketTimeoutException ignored) {
}
byte[] data = baos.toByteArray();
if (data.length > 3) {
String dataString = new String(data, "UTF-8");
boolean invalid = false;
if (dataString.startsWith("GET") || dataString.startsWith("POST"))
if (dataString.contains("HTTP/1."))
invalid = true;
if (invalid) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "closed " + client + " with error invalid data/HTTP");
os.write("Please use netcat");
os.newLine();
os.flush();
socketOfServer.close();
return;
}
Termbin.FileType ft = Termbin.FileType.TXT;
if (ImageUtils.isValidPNG(data))
@ -122,8 +130,8 @@ public class UploadServer {
os.write("Server Error");
}
} else {
os.write("Invalid data");
Logger.getLogger(getClass().getName()).log(Level.INFO, "closed " + client + " with error invalid data");
os.write("No Data Provided");
Logger.getLogger(getClass().getName()).log(Level.INFO, "closed " + client + " with error invalid data/length");
}
os.newLine();
os.flush();

View File

@ -37,7 +37,6 @@ public class Termbin {
createDatabase();
FileHandler fh = new FileHandler(conf.getString("accesslog") + ".%u.log", 5242880, 5, true);
// FileHandler fh = new FileHandler(conf.getString("accesslog") + ".log", true);
SimpleFormatter sf = new SimpleFormatter();
fh.setFormatter(sf);
accesslog.setUseParentHandlers(false);