proxy list taken out to config.json
This commit is contained in:
		
							parent
							
								
									9b3e1182ab
								
							
						
					
					
						commit
						00dca3eea7
					
				|  | @ -0,0 +1,6 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="VcsDirectoryMappings"> | ||||
|     <mapping directory="" vcs="Git" /> | ||||
|   </component> | ||||
| </project> | ||||
|  | @ -8,10 +8,12 @@ import java.awt.event.ActionEvent; | |||
| import java.awt.event.ActionListener; | ||||
| import java.io.IOException; | ||||
| import java.net.*; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
| 
 | ||||
| import static javax.swing.JOptionPane.showMessageDialog; | ||||
| import static org.dhaverdLogs.DhaverdLogs.*; | ||||
| import static org.proxy.loadConfig.getProxyList; | ||||
| import static org.proxy.loadConfig.getSocketPort; | ||||
| 
 | ||||
| public class Main { | ||||
|  | @ -53,7 +55,7 @@ public class Main { | |||
|         setLog(context, "Local Socket Address: "+serverSocket.getLocalSocketAddress(), true, false); | ||||
|     } | ||||
| 
 | ||||
|     public static void systemTray() throws IOException { | ||||
|     public static void systemTray() throws IOException, ParseException { | ||||
|         String context = "SystemTray"; | ||||
|         if(! SystemTray.isSupported() ) { | ||||
|             setLog(context,"System tray is unsupported!", true, false); | ||||
|  | @ -65,6 +67,17 @@ public class Main { | |||
|         } else { | ||||
|             trayFont = new Font("Arial", Font.PLAIN, 12); | ||||
|         } | ||||
|         List<String> 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); | ||||
|         } | ||||
|         /* | ||||
|         PopupMenu trayMenu = new PopupMenu(); | ||||
|         MenuItem proxyOn = new MenuItem("Proxy On"); | ||||
|         proxyOn.setFont(trayFont); | ||||
|  | @ -72,11 +85,14 @@ public class Main { | |||
|         MenuItem proxyOff = new MenuItem("Proxy Off"); | ||||
|         proxyOff.setFont(trayFont); | ||||
|         proxyOff.addActionListener(proxyOffListener()); | ||||
|         */ | ||||
|         MenuItem trayExit = new MenuItem("Exit"); | ||||
|         trayExit.setFont(trayFont); | ||||
|         trayExit.addActionListener(trayExitListener()); | ||||
|         /* | ||||
|         trayMenu.add(proxyOn); | ||||
|         trayMenu.add(proxyOff); | ||||
|         */ | ||||
|         trayMenu.add(trayExit); | ||||
|         Image icon; | ||||
|         if (isLinux){ | ||||
|  | @ -130,6 +146,20 @@ public class Main { | |||
|         return listener; | ||||
|     } | ||||
| 
 | ||||
|     public static ActionListener proxyListener(String proxyStr) { | ||||
|         ActionListener listener = new ActionListener() { | ||||
|             @Override | ||||
|             public void actionPerformed(ActionEvent e) { | ||||
|                 try { | ||||
|                     setProxy(proxyStr); | ||||
|                 } catch (IOException | InterruptedException ex) { | ||||
|                     exeptionActions("ProxyOn", ex); | ||||
|                 } | ||||
|             } | ||||
|         }; | ||||
|         return listener; | ||||
|     } | ||||
| 
 | ||||
|     public static ActionListener proxyOffListener() { | ||||
|         ActionListener listener = new ActionListener() { | ||||
|             @Override | ||||
|  | @ -144,6 +174,11 @@ public class Main { | |||
|         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 + "\""); | ||||
|     } | ||||
| 
 | ||||
|     public static void setProxyOn() 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 \"http://proxy.mcs.br:8080/array.dll?Get.Routing.Script\""); | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ import java.io.File; | |||
| import java.io.FileReader; | ||||
| import java.io.FileWriter; | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import static org.dhaverdLogs.DhaverdLogs.setLog; | ||||
| 
 | ||||
|  | @ -53,4 +54,14 @@ public class loadConfig { | |||
|         return Integer.parseInt(result); | ||||
|     } | ||||
| 
 | ||||
|     public static List<String> getProxyList() throws IOException, ParseException { | ||||
|         JSONObject jo = getJsonObjConfig(); | ||||
|         List<String> result = (List<String>) jo.get("proxyList"); | ||||
|         setLog("Config Loading", "Proxy list loaded. Items count: " + result.size(), true, false); | ||||
|         for (String line : result) { | ||||
|             setLog("Config Loading", "Proxy list item: " + line, false, true); | ||||
|         } | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue