Open GoogleCodeExporter opened 8 years ago
Daux2a: Additional benefit of this approach is that you don't have to make a
'GUI' that list all the publicly accessible files in jtorchat's menu. All you
need to do is just autogenerate an 'index.txt'.
One thing we should consider, is should we allow for 'html' to be displayed, or
enforce sending all files as txt files. (e.g. what if the user decided to embed
'malicious' javascript?)
Original comment by jtorc...@gmail.com
on 3 Mar 2012 at 4:16
So you understand what I mean. Here is some example (untested) code, that
illustrate the idea.
This code goes under TCServ.java
{{{
// If its a GET request, just treat it as a PAGE request
if (l.equals("GET")) {
PrintWriter out = new PrintWriter(s.getOutputStream());
String fileName = l.replaceFirst("/", "");
if (l.equals("")) {
fileName = "index";
} else {
//This is interpreted as a file name
fileName = URLDecoder.decode(fileName, "UTF-8");
}
if(fileName.indexOf('.')!=-1 || fileName.indexOf('/')!=-1) {
s.close();
}
out.println("HTTP/1.0 200 OK");
out.println("Content-Type: text/html");
out.println("Server: Bot");
// this blank line signals the end of the headers
out.println("");
// Send the HTML page
try{
Scanner scannerObj = new Scanner(new FileInputStream(Config.PAGE_DIR + fileName));
while (scannerObj.hasNextLine()) {
//result += "\n"+scannerObj.nextLine();
out.println(scannerObj.nextLine());
}
} catch (Exception FileNotFoundException) {
out.println("Resource Not Found");
}
// close send socket
out.close();
}
}}}
Just under this bit of code
{{{
if (l == null) {
Logger.log(Logger.SEVERE, "TCServ", "wtf");
s.close();
return;
}
}}}
Original comment by jtorc...@gmail.com
on 5 Mar 2012 at 12:22
Original issue reported on code.google.com by
jtorc...@gmail.com
on 3 Mar 2012 at 4:09