Skip to content
This repository has been archived by the owner on Feb 17, 2019. It is now read-only.

Commit

Permalink
updated console commands
Browse files Browse the repository at this point in the history
request handler standard
  • Loading branch information
sergix44 committed Apr 9, 2016
1 parent 4aec3cf commit 881ef2d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
33 changes: 26 additions & 7 deletions src/it/ksuploader/main/KSUploaderServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void main(String[] args) {
FileHandler loggerFileHandler = new FileHandler("./KSULog.txt", 10000000, 1, true);
loggerFileHandler.setFormatter(new LogFormatter());
loggerFileHandler.setLevel(Level.FINEST);
logger.setUseParentHandlers(false);

logger.addHandler(loggerFileHandler);

Expand Down Expand Up @@ -88,10 +89,9 @@ private static void bootstrap(String[] args) throws Exception {
} else {
if (
KSUploaderServer.config.getFolder().equals("") ||
KSUploaderServer.config.getPass().equals("") ||
Integer.toString(KSUploaderServer.config.getPort()).equals("") ||
KSUploaderServer.config.getWebUrl().equals(""))
{
KSUploaderServer.config.getPass().equals("") ||
Integer.toString(KSUploaderServer.config.getPort()).equals("") ||
KSUploaderServer.config.getWebUrl().equals("")) {
throw new Exception("Error reading config properties.");
} else {
System.out.println("Password: " + KSUploaderServer.config.getPass());
Expand All @@ -107,12 +107,31 @@ private static void bootstrap(String[] args) throws Exception {
private static void console() {
String cmd = "";
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (!cmd.equals("stop")) {
while (!cmd.equals("shutdown")) {
try {
cmd = in.readLine();
switch (cmd.split(" ")[0]) {
case "changepassword":
config.setPass(cmd.split(" ")[1]);
case "change-password":
if (config.setPass(cmd.split(" ")[1])) {
System.out.println("Password changed.");
} else {
System.out.println("Error.");
}
break;
case "get-password":
System.out.println(config.getPass());
break;
case "help":
case "?":
System.out.println("change-password <pass> - Change the server password");
System.out.println("get-password - Print current password");
System.out.println("shutdown - Stop the server");
break;
case "shutdown":
System.out.println("Shutting down...");
break;
default:
System.out.println("Invalid command.");
break;
}
} catch (IOException e) {
Expand Down
1 change: 0 additions & 1 deletion src/it/ksuploader/main/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void run() {
while (this.listen) {
try {
new RequestHandler(this.serverSocketChannel.accept()).start();
System.out.println("--------------------------------------------------------------------------------");
} catch (IOException e) {
this.logger.log(Level.WARNING, "Error during handling request", e);
}
Expand Down
11 changes: 6 additions & 5 deletions src/it/ksuploader/main/RequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public void run() {
this.input = new DataInputStream(socketChannel.socket().getInputStream());
this.output = new DataOutputStream(socketChannel.socket().getOutputStream());

// Syn string (password|fileLength|fileType)
// Syn string (password&fileLength&fileType)
this.logger.log(Level.INFO, "Waiting SYN");
String synInfo[] = input.readUTF().split("\\|");
String synInfo[] = input.readUTF().split("&");

// check correct SYN
if (synInfo.length != 3) {
Expand Down Expand Up @@ -105,8 +105,8 @@ public void run() {
this.output.writeUTF(Messages.OK.name());

// set file name
String fileName = new SimpleDateFormat("EEE-MMM-yyyy-hh-mm-ss-SSS").format(Calendar.getInstance().getTime());
fileName = fileName + "-" + new Random().nextInt(999999);
String fileName = new SimpleDateFormat("ddMMyy-HHmmssSS").format(Calendar.getInstance().getTime());
fileName = new Random().nextInt(9999) + "-" + fileName;

this.logger.log(Level.FINE, "Transfer started.");

Expand All @@ -115,11 +115,12 @@ public void run() {

boolean ret = readFromSocket(new File(KSUploaderServer.config.getFolder() + File.separator + fileName + format), flength);

this.logger.log(Level.FINE, "Transfer Ended.");
this.logger.log(Level.FINE, "Transfer ended.");

// return URL
if (ret) {
this.output.writeUTF(KSUploaderServer.config.getWebUrl() + fileName + format);
this.logger.log(Level.FINE, "Returned link -> " + KSUploaderServer.config.getWebUrl() + fileName + format);
} else {
this.output.writeUTF(Messages.UNKNOWN_ERROR.name());
}
Expand Down

0 comments on commit 881ef2d

Please sign in to comment.