Changeset 538


Ignore:
Timestamp:
11/27/13 10:31:19 (10 years ago)
Author:
jts21
Message:

Web browsers will also not automatically reload when the proxy settings change, so they have to be manually refreshed

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r536 r538  
    744744         */
    745745        private static void httpProxySetup(Item item) {
     746                try {
     747                        String[] data = proxyParse(item);
     748                        System.setProperty("http.proxyHost", data[0]);
     749                        System.setProperty("http.proxyPort", data[1]);
     750                        Browser.proxyAuth.setupHTTP(data[2], data[3]);
     751                } catch(Exception e) {
     752                        System.err.println("Failed to setup HTTP proxy");
     753                        e.printStackTrace();
     754                }
     755        }
     756       
     757        /**
     758         * Loads https proxy config from a frame
     759         * @author jts21
     760         */
     761        private static void httpsProxySetup(Item item) {
     762                String[] data = proxyParse(item);
     763                try {
     764                        System.setProperty("https.proxyHost", data[0]);
     765                        System.setProperty("https.proxyPort", data[1]);
     766                        Browser.proxyAuth.setupHTTPS(data[2], data[3]);
     767                } catch(Exception e) {
     768                        System.err.println("Failed to setup HTTPS proxy");
     769                        e.printStackTrace();
     770                }
     771        }
     772       
     773        /**
     774         * Loads proxy config from a frame,
     775         * @see httpProxySetup
     776         * @see httpsProxySetup
     777         * @param item
     778         * @return array of 4 strings, containing in order:
     779         *      host
     780         *      port
     781         *      user
     782         *      pass
     783         */
     784        private static String[] proxyParse(Item item) {
    746785                Frame child = item.getChild();
    747786                String host = null, port = null, user = null, pass = null;
     
    750789                        if(config instanceof Text) {
    751790                                String str = config.getText().trim().toLowerCase();
    752                                 if(str.startsWith("http_host:")) {
     791                                if(str.startsWith("host:")) {
    753792                                        if(host != null) {
    754                                                 MessageBay.displayMessage("http_host was defined multiple times!", Color.ORANGE);
    755                                         }
    756                                         host = str.substring(10).trim();
    757                                 } else if(str.startsWith("http_port:")) {
     793                                                MessageBay.displayMessage("host was defined multiple times!", Color.ORANGE);
     794                                        }
     795                                        host = str.substring(5).trim();
     796                                } else if(str.startsWith("port:")) {
    758797                                        if(port!= null) {
    759                                                 MessageBay.displayMessage("http_port was defined multiple times!", Color.ORANGE);
    760                                         }
    761                                         port = str.substring(10).trim();
    762                                 } else if(str.startsWith("http_user:")) {
     798                                                MessageBay.displayMessage("port was defined multiple times!", Color.ORANGE);
     799                                        }
     800                                        port = str.substring(5).trim();
     801                                } else if(str.startsWith("user:")) {
    763802                                        if(user != null) {
    764                                                 MessageBay.displayMessage("http_user was defined multiple times!", Color.ORANGE);
    765                                         }
    766                                         user = str.substring(11).trim();
    767                                 } else if(str.startsWith("http_pass:")) { // unencrypted password
     803                                                MessageBay.displayMessage("user was defined multiple times!", Color.ORANGE);
     804                                        }
     805                                        user = str.substring(6).trim();
     806                                } else if(str.startsWith("pass:")) { // unencrypted password
    768807                                        if(pass != null) {
    769                                                 MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
    770                                         }
    771                                         pass = str.substring(11).trim();
     808                                                MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
     809                                        }
     810                                        pass = str.substring(6).trim();
    772811                                } else if(str.startsWith("@iw:")) {           // widget
    773812                                        // check if it's a password widget
     
    777816                                                                passwordWidget = (Password) InteractiveWidget.createWidget((Text)config);
    778817                                                                if(pass != null) {
    779                                                                         MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
     818                                                                        MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
    780819                                                                }
    781820                                                                pass = passwordWidget.getPassword();
     
    798837                                        }
    799838                                        if(pass != null) {
    800                                                 MessageBay.displayMessage("http_pass was defined multiple times!", Color.ORANGE);
     839                                                MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
    801840                                        }
    802841                                        pass = passwordWidget.getPassword();
     
    805844                }
    806845                if(host == null) {
    807                         MessageBay.displayMessage("http_host was not defined!", Color.ORANGE);
     846                        MessageBay.displayMessage("host was not defined!", Color.ORANGE);
    808847                }
    809848                if(port == null) {
    810                         MessageBay.displayMessage("http_port was not defined! (defaulted to 80)", Color.ORANGE);
     849                        MessageBay.displayMessage("port was not defined! (defaulted to 80)", Color.ORANGE);
    811850                        port = "80";
    812851                }
    813852                if(user == null) {
    814                         MessageBay.displayMessage("http_user was not defined!", Color.ORANGE);
     853                        MessageBay.displayMessage("user was not defined!", Color.ORANGE);
    815854                }
    816855                if(pass == null) {
    817                         MessageBay.displayMessage("http_pass was not defined!", Color.ORANGE);
    818                 }
    819                 System.setProperty("http.proxyHost", host);
    820                 System.setProperty("http.proxyPort", port);
    821                 Browser.proxyAuth.setupHTTP(user, pass);
    822         }
    823        
    824         /**
    825          * Loads https proxy config from a frame
    826          * @author jts21
    827          */
    828         private static void httpsProxySetup(Item item) {
    829                 Frame child = item.getChild();
    830                 if(child == null) {
    831                         return;
    832                 }
    833                 String host = null, port = null, user = null, pass = null;
    834                 Password passwordWidget = null;
    835                 for(Item config : child.getAllItems()) {
    836                         if(config instanceof Text) {
    837                                 String str = config.getText().trim().toLowerCase();
    838                                 if(str.startsWith("http_host:")) {
    839                                         if(host != null) {
    840                                                 MessageBay.displayMessage("https_host was defined multiple times!", Color.ORANGE);
    841                                         }
    842                                         host = str.substring(10).trim();
    843                                 } else if(str.startsWith("https_port:")) {
    844                                         if(port!= null) {
    845                                                 MessageBay.displayMessage("https_port was defined multiple times!", Color.ORANGE);
    846                                         }
    847                                         port = str.substring(10).trim();
    848                                 } else if(str.startsWith("https_user:")) {
    849                                         if(user != null) {
    850                                                 MessageBay.displayMessage("https_user was defined multiple times!", Color.ORANGE);
    851                                         }
    852                                         user = str.substring(11).trim();
    853                                 } else if(str.startsWith("https_pass:")) { // unencrypted password
    854                                         if(pass != null) {
    855                                                 MessageBay.displayMessage("https_pass was defined multiple times!", Color.ORANGE);
    856                                         }
    857                                         pass = str.substring(11).trim();
    858                                 } else if(str.startsWith("@iw:")) {           // widget
    859                                         // check if it's a password widget
    860                                         if(str.substring(4).trim().startsWith("org.expeditee.items.widgets.password")) {
    861                                                 if(passwordWidget == null) {
    862                                                         try {
    863                                                                 passwordWidget = (Password) InteractiveWidget.createWidget((Text)config);
    864                                                                 if(pass != null) {
    865                                                                         MessageBay.displayMessage("https_pass was defined multiple times!", Color.ORANGE);
    866                                                                 }
    867                                                                 pass = passwordWidget.getPassword();
    868                                                         } catch (Exception e) {
    869                                                                 e.printStackTrace();
    870                                                         }
    871                                                 }
    872                                         }
    873                                 }
    874                         } else if(config instanceof WidgetCorner || config instanceof WidgetEdge) {
    875                                 if(passwordWidget == null) {
    876                                         InteractiveWidget iw;
    877                                         if(config instanceof WidgetCorner) {
    878                                                 iw = ((WidgetCorner)config).getWidgetSource();
    879                                         } else {
    880                                                 iw = ((WidgetEdge)config).getWidgetSource();
    881                                         }
    882                                         if(iw instanceof Password) {
    883                                                 passwordWidget = (Password) iw;
    884                                         }
    885                                         if(pass != null) {
    886                                                 MessageBay.displayMessage("https_pass was defined multiple times!", Color.ORANGE);
    887                                         }
    888                                         pass = passwordWidget.getPassword();
    889                                 }
    890                         }
    891                 }
    892                 if(host == null) {
    893                         MessageBay.displayMessage("https_host was not defined!", Color.ORANGE);
    894                 }
    895                 if(port == null) {
    896                         MessageBay.displayMessage("https_port was not defined! (defaulted to 80)", Color.ORANGE);
    897                         port = "80";
    898                 }
    899                 if(user == null) {
    900                         MessageBay.displayMessage("https_user was not defined!", Color.ORANGE);
    901                 }
    902                 if(pass == null) {
    903                         MessageBay.displayMessage("https_pass was not defined!", Color.ORANGE);
    904                 }
    905                 System.setProperty("https.proxyHost", host);
    906                 System.setProperty("https.proxyPort", port);
    907                 Browser.proxyAuth.setupHTTPS(user, pass);
    908         }
    909        
    910        
     856                        MessageBay.displayMessage("pass was not defined!", Color.ORANGE);
     857                }
     858                return new String[] { host, port, user, pass };
     859        }
    911860
    912861        private static List<Text> getStyle(Frame child) {
  • trunk/src/org/expeditee/io/ProxyAuth.java

    r536 r538  
    77
    88        private String httpUser = null, httpPass = null, httpsUser = null, httpsPass = null;
     9        private int attempts = 0;
    910       
    1011        public ProxyAuth() {
     
    1617                // currently just chooses whichever one is set, preferentially http
    1718                System.out.println("Authenticating");
    18                 return new PasswordAuthentication(httpUser != null ? httpUser : httpsUser, httpPass != null ? httpPass.toCharArray() : httpsPass.toCharArray());
     19                // stop it from breaking from a redirect loop
     20                attempts++;
     21                if(attempts > 5) {
     22                        return null;
     23                }
     24                String user = httpUser != null ? httpUser : httpsUser;
     25                char[] pass = httpPass != null ? httpPass.toCharArray() : (httpsPass != null ? httpsPass.toCharArray() : null);
     26                if(user == null || user.length() == 0 || pass == null || pass.length == 0) {
     27                        return null;
     28                }
     29                return new PasswordAuthentication(user, pass);
    1930        }
    2031       
     
    2334                this.httpUser = user;
    2435                this.httpPass = pass;
     36                attempts = 0;
    2537        }
    2638       
     
    2941                this.httpsUser = user;
    3042                this.httpsPass = pass;
     43                attempts = 0;
    3144        }
    3245}
Note: See TracChangeset for help on using the changeset viewer.