diff --git a/out/artifacts/proxy/proxy.jar b/out/artifacts/proxy/proxy.jar index 50ccf6b..5fa5d19 100644 Binary files a/out/artifacts/proxy/proxy.jar and b/out/artifacts/proxy/proxy.jar differ diff --git a/out/artifacts/proxy/res/icon off.png b/out/artifacts/proxy/res/icon off.png new file mode 100644 index 0000000..fe6165c Binary files /dev/null and b/out/artifacts/proxy/res/icon off.png differ diff --git a/out/artifacts/proxy/res/icon on blue.png b/out/artifacts/proxy/res/icon on blue.png new file mode 100644 index 0000000..5a983f1 Binary files /dev/null and b/out/artifacts/proxy/res/icon on blue.png differ diff --git a/out/artifacts/proxy/res/icon on.png b/out/artifacts/proxy/res/icon on.png new file mode 100644 index 0000000..3c1b64e Binary files /dev/null and b/out/artifacts/proxy/res/icon on.png differ diff --git a/out/production/proxy/org/proxy/Main$1.class b/out/production/proxy/org/proxy/Main$1.class deleted file mode 100644 index 208f97b..0000000 Binary files a/out/production/proxy/org/proxy/Main$1.class and /dev/null differ diff --git a/out/production/proxy/org/proxy/Main$2.class b/out/production/proxy/org/proxy/Main$2.class deleted file mode 100644 index 5dbca01..0000000 Binary files a/out/production/proxy/org/proxy/Main$2.class and /dev/null differ diff --git a/out/production/proxy/org/proxy/Main$3$1.class b/out/production/proxy/org/proxy/Main$3$1.class deleted file mode 100644 index 736b168..0000000 Binary files a/out/production/proxy/org/proxy/Main$3$1.class and /dev/null differ diff --git a/out/production/proxy/org/proxy/Main$3.class b/out/production/proxy/org/proxy/Main$3.class deleted file mode 100644 index da35481..0000000 Binary files a/out/production/proxy/org/proxy/Main$3.class and /dev/null differ diff --git a/out/production/proxy/org/proxy/Main.class b/out/production/proxy/org/proxy/Main.class index a5c8b3a..658a574 100644 Binary files a/out/production/proxy/org/proxy/Main.class and b/out/production/proxy/org/proxy/Main.class differ diff --git a/src/org/proxy/Main.java b/src/org/proxy/Main.java index 1f241ec..d3e62a0 100644 --- a/src/org/proxy/Main.java +++ b/src/org/proxy/Main.java @@ -2,11 +2,11 @@ package org.proxy; import org.json.simple.parser.ParseException; -import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.net.*; import java.util.List; import java.util.Locale; @@ -32,16 +32,37 @@ public class Main { } public static Thread currentThread = null; + public static String currentProxyPub = " proxy is off"; - public static void main(String[] args) throws IOException, ParseException { + public static void main(String[] args) throws IOException, ParseException, InterruptedException { setLogDir("logs"); setLogName("startup"); logCleaner(getDeleteTime()); bindSocket(); repeatTime = getRepeatTime(); + currentProxyPub = getCurrentProxy(); + setLog("Proxy Checker", "Current proxy: " + currentProxyPub, true, false); systemTray(); } + public static String getCurrentProxy() throws InterruptedException, IOException { + String currentProxy = " proxy is off"; + Process proc = Runtime.getRuntime().exec("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\""); + proc.waitFor(); + BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream())); + String s; + String proxyLine = ""; + while ((s = stdInput.readLine()) != null) { + if (s.contains("AutoConfigURL")){ + proxyLine = s.replace(" ", ";"); + } + } + String[] abc = proxyLine.split(";"); + if (abc.length == 4 && abc[3] != null) currentProxy = abc[3]; + proc.destroy(); + return currentProxy; + } + public static void bindSocket() throws IOException, ParseException { String context = "BindSocket"; InetAddress inetAddress = InetAddress.getByName("localhost"); @@ -71,35 +92,25 @@ public class Main { trayFont = new Font("Arial", Font.PLAIN, 12); } List proxyList = getProxyList(); - int counter = 1; PopupMenu trayMenu = new PopupMenu(); for (String prox : proxyList){ MenuItem proxy = new MenuItem(prox); - counter++; proxy.setFont(trayFont); proxy.addActionListener(proxyListener(prox)); trayMenu.add(proxy); } - MenuItem stopbutton = new MenuItem("Stop"); - stopbutton.setFont(trayFont); - stopbutton.addActionListener(stopListener()); - trayMenu.add(stopbutton); + MenuItem stopButton = new MenuItem("Stop"); + stopButton.setFont(trayFont); + stopButton.addActionListener(stopListener()); + trayMenu.add(stopButton); MenuItem trayExit = new MenuItem("Exit"); trayExit.setFont(trayFont); trayExit.addActionListener(trayExitListener()); trayMenu.add(trayExit); Image icon; - if (isLinux){ - icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon.png"); - } else { - icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon.png"); - } - trayIcon = new TrayIcon(icon, "Current proxy: proxy is off", trayMenu); - if (isLinux){ - trayIcon.setImageAutoSize(false); - } else { - trayIcon.setImageAutoSize(true); - } + icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon off.png"); + trayIcon = new TrayIcon(icon, "Current proxy: " + currentProxyPub, trayMenu); + trayIcon.setImageAutoSize(!isLinux); SystemTray tray = SystemTray.getSystemTray(); try { tray.add(trayIcon); @@ -110,31 +121,41 @@ public class Main { } public static ActionListener trayExitListener() { - ActionListener listener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - try { - setLog("Program","Closing server socket...", true, false); - setLog( "Program","Exiting program", true, false); - serverSocket.close(); - } catch (IOException ex) { - exeptionActions("TrayExitListener", ex); - } - closeThread(); - System.exit(0); + return e -> { + try { + setLog("Program","Closing server socket...", true, false); + setLog( "Program","Exiting program", true, false); + serverSocket.close(); + } catch (IOException ex) { + exeptionActions("TrayExitListener", ex); } + closeThread(); + System.exit(0); }; - return listener; } public static ActionListener stopListener() { - ActionListener listener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - closeThread(); - trayIcon.setToolTip("Current proxy: proxy is off"); + return e -> { + closeThread(); + try { + setLog("Stop Listener", "Proxy setter now is off", true, false); + } catch (IOException ex) { + exeptionActions("Stop Listener", ex); } + Image icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon off.png"); + trayIcon.setImage(icon); + currentThread = new Thread(() -> { + while(true){ + try { + currentProxyPub = getCurrentProxy(); + trayIcon.setToolTip("Current proxy: " + currentProxyPub); + Thread.sleep(repeatTime); + } catch (InterruptedException | IOException ex) { + exeptionActions("Stop Listener", ex); + } + } + }); + currentThread.start(); }; - return listener; } public static void closeThread(){ if (currentThread != null){ @@ -144,36 +165,31 @@ public class Main { } public static ActionListener proxyListener(String proxyStr) { - ActionListener listener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if (currentThread != null){ - currentThread.stop(); - } - currentThread = new Thread(new Runnable() { - @Override - public void run() { - while(true){ - try { - setProxy(proxyStr); - Thread.sleep(repeatTime); - } catch (InterruptedException | IOException ex) { - exeptionActions(proxyStr, ex); - } - } + return e -> { + closeThread(); + currentThread = new Thread(() -> { + while(true){ + try { + currentProxyPub = getCurrentProxy(); + if (!currentProxyPub.equals(proxyStr)) setProxy(proxyStr); + Image icon = Toolkit.getDefaultToolkit().getImage("res" + osSeparator + "icon on blue.png"); + trayIcon.setImage(icon); + currentProxyPub = getCurrentProxy(); + trayIcon.setToolTip("Current proxy: " + currentProxyPub); + Thread.sleep(repeatTime); + } catch (InterruptedException | IOException ex) { + exeptionActions( "Set proxy: " + proxyStr, ex); } - }); - currentThread.start(); - } + } + }); + currentThread.start(); }; - return listener; } public static void setProxy(String proxyStr) throws IOException, InterruptedException { execute("reg delete \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v AutoConfigURL /f"); execute("reg add \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\" /v AutoConfigURL /t REG_SZ /d \"" + proxyStr + "\""); - setLog("setProxy", "Proxy is set on: " + proxyStr, true, false); - trayIcon.setToolTip("Current proxy: " + proxyStr); + setLog("Set Proxy", "Proxy is set on: " + proxyStr, true, false); } public static void execute(String command) throws IOException, InterruptedException {