Maybe a mistake?

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 2 years ago
parent 986214bf66
commit f10e80c7f7
  1. 115
      sigServer.java

@ -84,71 +84,73 @@ public class sigServer {
if (boundary.length()>0) { if (boundary.length()>0) {
if (line.equals(boundary)) { if (line.equals(boundary)) {
truncateUntilBoundary=true; truncateUntilBoundary=true;
System.out.println("Boundary found.");
} }
} }
} else } else {
if (line.contains("Content-Disposition: ")||line.contains("Content-Type: ")) { if (line.contains("Content-Disposition: ")||line.contains("Content-Type: ")) {
if (line.contains("filename=")) { if (line.contains("filename=")) {
filename=line.substring(line.indexOf("filename=")+"filename=".length()+1); filename=line.substring(line.indexOf("filename=")+"filename=".length()+1);
filename = filename.substring(0,filename.length()-1); filename = filename.substring(0,filename.length()-1);
int dotPosition=0; int dotPosition=0;
if (filename.contains(".")) { if (filename.contains(".")) {
for (int i=filename.length()-1;i>=0;i--) { for (int i=filename.length()-1;i>=0;i--) {
if (filename.charAt(i)=='.') { if (filename.charAt(i)=='.') {
dotPosition=i; dotPosition=i;
break; break;
}
} }
} }
filename="upload"+System.nanoTime()+filename.substring(dotPosition);
System.out.println("Filename: "+filename);
} else {
System.out.println(line);
} }
filename="upload"+System.nanoTime()+filename.substring(dotPosition);
System.out.println("Filename: "+filename);
} else { } else {
System.out.println(line); File myFile = new File(new File(sigPlace.OUTDIR,sigPlace.UPLOADSDIR),filename);
} // check if file exist, otherwise create the file before writing
} else { myFile.mkdirs();
File myFile = new File(new File(sigPlace.OUTDIR,sigPlace.UPLOADSDIR),filename); if (!myFile.exists()) {
// check if file exist, otherwise create the file before writing myFile.createNewFile();
myFile.mkdirs(); } else {
if (!myFile.exists()) { myFile.delete();
myFile.createNewFile(); myFile.createNewFile();
} else {
myFile.delete();
myFile.createNewFile();
}
stream = new FileOutputStream(myFile);
char[] buffer = new char[1024];
int count;
boolean wroteData=false;
while ((count = in.read(buffer))>0) {
//stream.write(in.read(buffer));
//stream.write(buffer.,0,count);
String buf = new String(buffer);
byte[] data = buf.getBytes("ISO-8859-1");
stream.write(data,0,count);
wroteData=true;
if (buf.contains(boundary)) {
System.out.println("");
System.out.println("<...>");
System.out.println("");
System.out.println(new String(data,StandardCharsets.UTF_8));
break;
} }
} stream = new FileOutputStream(myFile);
stream.close(); char[] buffer = new char[1024];
int count;
boolean wroteData=false;
while ((count = in.read(buffer))>0) {
//stream.write(in.read(buffer));
//stream.write(buffer.,0,count);
String buf = new String(buffer);
byte[] data = buf.getBytes("ISO-8859-1");
stream.write(data,0,count);
wroteData=true;
if (buf.contains(boundary)) {
System.out.println("");
System.out.println("<...>");
System.out.println("");
System.out.println(new String(data,StandardCharsets.UTF_8));
break;
}
}
stream.close();
if (!wroteData) { if (!wroteData) {
System.out.println("Upload failed!"); System.out.println("Upload failed!");
in.close(); in.close();
CreateRequest(client,"400","Bad Request",Paths.get(sigPlace.OUTDIR,"testfile.html")); CreateRequest(client,"400","Bad Request",Paths.get(sigPlace.OUTDIR,"testfile.html"));
return; return;
} else { } else {
System.out.println("Saving upload to "+sigPlace.UPLOADSDIR+" directory."); System.out.println("Saving upload to "+sigPlace.UPLOADSDIR+" directory.");
if (filename.contains(".png")) { if (filename.contains(".png")) {
ArcadeReader.submitToDatabase(Paths.get(sigPlace.OUTDIR,sigPlace.UPLOADSDIR,filename)); ArcadeReader.submitToDatabase(Paths.get(sigPlace.OUTDIR,sigPlace.UPLOADSDIR,filename));
System.out.println("Submitted to the database!"); System.out.println("Submitted to the database!");
}
} }
filename=null;
} }
filename=null;
} }
} }
if (line.contains("Content-Length: ")) { if (line.contains("Content-Length: ")) {
@ -157,8 +159,7 @@ public class sigServer {
} }
if (line.contains("Content-Type:")) { if (line.contains("Content-Type:")) {
if (line.contains("Content-Type: multipart/form-data; boundary=")) { if (line.contains("Content-Type: multipart/form-data; boundary=")) {
boundary=line.substring("Content-Type: multipart/form-data; boundary=".length()); boundary="--"+line.substring("Content-Type: multipart/form-data; boundary=".length());
System.out.println("Boundary set to "+boundary);
} else } else
if (line.contains("application/json")){ if (line.contains("application/json")){
isApplication=true; isApplication=true;

Loading…
Cancel
Save