Changeset 542


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

Switch ProxyAuth to using the same details for HTTP an HTTPS, since otherwise HTTPS websites will be inaccessible if only HTTP proxy is set

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

Legend:

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

    r538 r542  
    707707                                } else if (attribute.equals("colorwheel")) {
    708708                                        Item.COLOR_WHEEL = getColorWheel(item);
    709                                 } else if (attribute.equals("http_proxy")) {
    710                                         httpProxySetup(item);
    711                                 } else if (attribute.equals("https_proxy")) {
    712                                         httpsProxySetup(item);
     709                                } else if (attribute.equals("proxy")) {
     710                                        proxySetup(item);
    713711                                } else if (attribute.equals("fillcolorwheel")) {
    714712                                        Item.FILL_COLOR_WHEEL = getColorWheel(item);
     
    740738
    741739        /**
    742          * Loads http proxy config from a frame
     740         * Loads proxy config from a frame
    743741         * @author jts21
    744742         */
    745         private static void httpProxySetup(Item item) {
     743        private static void proxySetup(Item item) {
    746744                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]);
     745                        Frame child = item.getChild();
     746                        String host = null, port = null, user = null, pass = null;
     747                        Password passwordWidget = null;
     748                        for(Item config : child.getAllItems()) {
     749                                if(config instanceof Text) {
     750                                        String str = config.getText().trim().toLowerCase();
     751                                        if(str.startsWith("host:")) {
     752                                                if(host != null) {
     753                                                        MessageBay.displayMessage("host was defined multiple times!", Color.ORANGE);
     754                                                }
     755                                                host = str.substring(5).trim();
     756                                        } else if(str.startsWith("port:")) {
     757                                                if(port!= null) {
     758                                                        MessageBay.displayMessage("port was defined multiple times!", Color.ORANGE);
     759                                                }
     760                                                port = str.substring(5).trim();
     761                                        } else if(str.startsWith("user:")) {
     762                                                if(user != null) {
     763                                                        MessageBay.displayMessage("user was defined multiple times!", Color.ORANGE);
     764                                                }
     765                                                user = str.substring(6).trim();
     766                                        } else if(str.startsWith("pass:")) {    // unencrypted password
     767                                                if(pass != null) {
     768                                                        MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
     769                                                }
     770                                                pass = str.substring(6).trim();
     771                                        } else if(str.startsWith("@iw:")) {             // widget
     772                                                // check if it's a password widget
     773                                                if(str.substring(4).trim().startsWith("org.expeditee.items.widgets.password")) {
     774                                                        if(passwordWidget == null) {
     775                                                                try {
     776                                                                        passwordWidget = (Password) InteractiveWidget.createWidget((Text)config);
     777                                                                        if(pass != null) {
     778                                                                                MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
     779                                                                        }
     780                                                                        pass = passwordWidget.getPassword();
     781                                                                } catch (Exception e) {
     782                                                                        e.printStackTrace();
     783                                                                }
     784                                                        }
     785                                                }
     786                                        }
     787                                } else if(config instanceof WidgetCorner || config instanceof WidgetEdge) {
     788                                        if(passwordWidget == null) {
     789                                                InteractiveWidget iw;
     790                                                if(config instanceof WidgetCorner) {
     791                                                        iw = ((WidgetCorner)config).getWidgetSource();
     792                                                } else {
     793                                                        iw = ((WidgetEdge)config).getWidgetSource();
     794                                                }
     795                                                if(iw instanceof Password) {
     796                                                        passwordWidget = (Password) iw;
     797                                                }
     798                                                if(pass != null) {
     799                                                        MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
     800                                                }
     801                                                pass = passwordWidget.getPassword();
     802                                        }
     803                                }
     804                        }
     805                        if(host == null) {
     806                                MessageBay.displayMessage("host was not defined!", Color.ORANGE);
     807                        }
     808                        if(port == null) {
     809                                MessageBay.displayMessage("port was not defined! (defaulted to 80)", Color.ORANGE);
     810                                port = "80";
     811                        }
     812                        if(user == null) {
     813                                MessageBay.displayMessage("user was not defined!", Color.ORANGE);
     814                        }
     815                        if(pass == null) {
     816                                MessageBay.displayMessage("pass was not defined!", Color.ORANGE);
     817                        }
     818                        // TODO: Is it possible to have different host/port for http/https protocols for a proxy server?
     819                        System.setProperty("http.proxyHost", host);
     820                        System.setProperty("http.proxyPort", port);
     821                        System.setProperty("https.proxyHost", host);
     822                        System.setProperty("https.proxyPort", port);
     823                        Browser.proxyAuth.setup(user, pass);
    751824                } catch(Exception e) {
    752                         System.err.println("Failed to setup HTTP proxy");
     825                        System.err.println("Failed to setup proxy");
    753826                        e.printStackTrace();
    754827                }
    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) {
    785                 Frame child = item.getChild();
    786                 String host = null, port = null, user = null, pass = null;
    787                 Password passwordWidget = null;
    788                 for(Item config : child.getAllItems()) {
    789                         if(config instanceof Text) {
    790                                 String str = config.getText().trim().toLowerCase();
    791                                 if(str.startsWith("host:")) {
    792                                         if(host != null) {
    793                                                 MessageBay.displayMessage("host was defined multiple times!", Color.ORANGE);
    794                                         }
    795                                         host = str.substring(5).trim();
    796                                 } else if(str.startsWith("port:")) {
    797                                         if(port!= null) {
    798                                                 MessageBay.displayMessage("port was defined multiple times!", Color.ORANGE);
    799                                         }
    800                                         port = str.substring(5).trim();
    801                                 } else if(str.startsWith("user:")) {
    802                                         if(user != null) {
    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
    807                                         if(pass != null) {
    808                                                 MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
    809                                         }
    810                                         pass = str.substring(6).trim();
    811                                 } else if(str.startsWith("@iw:")) {           // widget
    812                                         // check if it's a password widget
    813                                         if(str.substring(4).trim().startsWith("org.expeditee.items.widgets.password")) {
    814                                                 if(passwordWidget == null) {
    815                                                         try {
    816                                                                 passwordWidget = (Password) InteractiveWidget.createWidget((Text)config);
    817                                                                 if(pass != null) {
    818                                                                         MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
    819                                                                 }
    820                                                                 pass = passwordWidget.getPassword();
    821                                                         } catch (Exception e) {
    822                                                                 e.printStackTrace();
    823                                                         }
    824                                                 }
    825                                         }
    826                                 }
    827                         } else if(config instanceof WidgetCorner || config instanceof WidgetEdge) {
    828                                 if(passwordWidget == null) {
    829                                         InteractiveWidget iw;
    830                                         if(config instanceof WidgetCorner) {
    831                                                 iw = ((WidgetCorner)config).getWidgetSource();
    832                                         } else {
    833                                                 iw = ((WidgetEdge)config).getWidgetSource();
    834                                         }
    835                                         if(iw instanceof Password) {
    836                                                 passwordWidget = (Password) iw;
    837                                         }
    838                                         if(pass != null) {
    839                                                 MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
    840                                         }
    841                                         pass = passwordWidget.getPassword();
    842                                 }
    843                         }
    844                 }
    845                 if(host == null) {
    846                         MessageBay.displayMessage("host was not defined!", Color.ORANGE);
    847                 }
    848                 if(port == null) {
    849                         MessageBay.displayMessage("port was not defined! (defaulted to 80)", Color.ORANGE);
    850                         port = "80";
    851                 }
    852                 if(user == null) {
    853                         MessageBay.displayMessage("user was not defined!", Color.ORANGE);
    854                 }
    855                 if(pass == null) {
    856                         MessageBay.displayMessage("pass was not defined!", Color.ORANGE);
    857                 }
    858                 return new String[] { host, port, user, pass };
    859828        }
    860829
  • trunk/src/org/expeditee/io/ProxyAuth.java

    r538 r542  
    3030        }
    3131       
    32         public void setupHTTP(String user, String pass) {
    33                 System.out.println("setup HTTP");
     32        public void setup(String user, String pass) {
     33                System.out.println("setup proxy");
    3434                this.httpUser = user;
    3535                this.httpPass = pass;
    36                 attempts = 0;
    37         }
    38        
    39         public void setupHTTPS(String user, String pass) {
    40                 System.out.println("setup HTTPS");
    4136                this.httpsUser = user;
    4237                this.httpsPass = pass;
Note: See TracChangeset for help on using the changeset viewer.