From 89fb07c961be50f00559197dbd0a344fbba466d2 Mon Sep 17 00:00:00 2001 From: Jose Damico Date: Thu, 8 May 2014 14:58:54 -0300 Subject: [PATCH] Added command line parameters support. --- .../org/jdamico/socks/server/StartProxy.class | Bin 672 -> 1364 bytes .../org/jdamico/socks/server/StartProxy.java | 23 +++++++++++++++--- .../socks/server/commons/DebugLog.java | 8 +++--- .../server/impl/ProxyServerInitiator.java | 2 +- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/java-socks-proxy-server/bin/org/jdamico/socks/server/StartProxy.class b/java-socks-proxy-server/bin/org/jdamico/socks/server/StartProxy.class index 38a58a58efe39805871a9d1ff55a60019ba1d468..ab20fc672fca0bc3745027c07040b2b08dace37b 100644 GIT binary patch literal 1364 zcma)5U2hvj6g?B$S!dZajT48aX{kvYuuYtW(DKo^p|nYQ*FQdz zQ5a}H(ZQ3%Pn3D8jDL_ylkOY+?74%yz{O+vRQf#`cm3}Uk5!NgTu`w*?5QnvIOw)@ zS3o=xC^my$7>DVmK(1Qr2;}eUBQ*tqcRUm@DKOIxW3@Mk4wd=d;sr`=9mrlsn$Uia zjFZhQjEfvDdbofhL#025iNH$xe~{jwdnChHV4?a``;7cSYQng?QR@`3Ah7*IRzfA! zmA*8IssuWUWPH?M4a%Biq*7&))yg0tta79t%Rw)tTl_fe4vb7g9k02#gv$;V$GS93 z0f!Q;ftvFR(Wjwr(Wi~YCfDaIi8K zeA{0k_Z!@o+)TjZI+>YWOlKAg=Twa#KHnBp zsK3I@e<8&T;td@zixM5DFo*dO_%G%!(6%$XeA+CPck8bUzo1dit)JlCy~Zi7HtTu2 zznx#qpW-@6y+C>ISJYNd;J<)7+WmoBKQ6t(=O?)Rl98uT!z%7Dwk5xwttI4{)xiQ! zFLAfX=Q8`TMBghE=vCarHEhz-!g9uXGwaU|zQSEb$>RaO#yv)NaG%c>TQiR`wzikaQ9yF?0VYXT4h9KE z22MjGb3FqfG~{9sWsu@w;A4^5PWKaZ>Obki@;5#FU diff --git a/java-socks-proxy-server/src/org/jdamico/socks/server/StartProxy.java b/java-socks-proxy-server/src/org/jdamico/socks/server/StartProxy.java index 598e17d..288667b 100644 --- a/java-socks-proxy-server/src/org/jdamico/socks/server/StartProxy.java +++ b/java-socks-proxy-server/src/org/jdamico/socks/server/StartProxy.java @@ -7,13 +7,30 @@ public class StartProxy { - public static boolean enableLog = false; + public static boolean enableDebugLog = false; public static void main(String[] args) { + /* + * enableDebugLog + * listenPort + */ - enableLog = true; + int port = Constants.LISTEN_PORT; - new ProxyServerInitiator(Constants.LISTEN_PORT, Constants.PROXY_HOST, Constants.PROXY_PORT ).start(); + String noParamsMsg = "Unable to parse command-line parameters, using default configuration."; + + if(args.length == 2){ + try { + String prePort = args[0].trim(); + port = Integer.parseInt(prePort); + String preDebug = args[1].trim(); + enableDebugLog = Boolean.parseBoolean(preDebug); + } catch (Exception e) { + System.out.println(noParamsMsg); + } + }else System.out.println(noParamsMsg); + + new ProxyServerInitiator(port).start(); } } diff --git a/java-socks-proxy-server/src/org/jdamico/socks/server/commons/DebugLog.java b/java-socks-proxy-server/src/org/jdamico/socks/server/commons/DebugLog.java index 3a65f8b..8ff73a0 100644 --- a/java-socks-proxy-server/src/org/jdamico/socks/server/commons/DebugLog.java +++ b/java-socks-proxy-server/src/org/jdamico/socks/server/commons/DebugLog.java @@ -24,12 +24,12 @@ public static DebugLog getInstance(){ public void println( String txt ) { - if( StartProxy.enableLog ) print( txt + Constants.EOL ); + if( StartProxy.enableDebugLog ) print( txt + Constants.EOL ); } public void print( String txt ) { - if( !StartProxy.enableLog ) return; + if( !StartProxy.enableDebugLog ) return; if( txt == null ) return; System.out.print( txt ); } @@ -37,13 +37,13 @@ public void print( String txt ) { ///////////////////////////////////////////////// public void error( String txt ) { - if( StartProxy.enableLog ) println( "Error : " + txt ); + if( StartProxy.enableDebugLog ) println( "Error : " + txt ); } ///////////////////////////////////////////////// public void error( Exception e ) { - if( !StartProxy.enableLog ) return; + if( !StartProxy.enableDebugLog ) return; println( "ERROR : " + e.toString() ); e.printStackTrace(); } diff --git a/java-socks-proxy-server/src/org/jdamico/socks/server/impl/ProxyServerInitiator.java b/java-socks-proxy-server/src/org/jdamico/socks/server/impl/ProxyServerInitiator.java index c618f8d..304e126 100644 --- a/java-socks-proxy-server/src/org/jdamico/socks/server/impl/ProxyServerInitiator.java +++ b/java-socks-proxy-server/src/org/jdamico/socks/server/impl/ProxyServerInitiator.java @@ -28,7 +28,7 @@ public class ProxyServerInitiator implements Runnable public int getPort() { return m_nPort; } - public ProxyServerInitiator(int listenPort, String proxyHost, int proxyPort) { + public ProxyServerInitiator(int listenPort) { m_lock = this; m_nPort = listenPort;