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(); JSONObject uploadserver = new JSONObject();
uploadserver.put("port", 8888); uploadserver.put("port", 8888);
uploadserver.put("timeout", 5);
uploadserver.put("bind", "0.0.0.0"); uploadserver.put("bind", "0.0.0.0");
this.put("uploadserver", uploadserver); this.put("uploadserver", uploadserver);

View File

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

View File

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