Changeset 20618 for greenstone3

Show
Ignore:
Timestamp:
17.09.2009 16:24:39 (11 years ago)
Author:
ak19
Message:

1. Changes to get localhost to be recognised on Linux and the hostname to be recognised on Windows. Multiple allowed host values are inserted into the configfile (e.g. llssite.cfg) and these are used in httpd.conf. 2. Fixed errors: the Address Resolution Method part of the GSI dialog should not be deactivated when the Allow External Connections is checked.

Location:
greenstone3/trunk/src/java/org/greenstone/server
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/server/Server2.java

    r20604 r20618  
    88import java.io.InputStreamReader; 
    99import java.io.IOException; 
     10import java.net.InetAddress; 
    1011import java.net.ServerSocket; 
    1112import java.net.Socket; 
     13import java.net.UnknownHostException; 
    1214import java.net.URL; 
    1315//import java.net.URLConnection; 
     
    207209        //reloadConfigProperties(); 
    208210        port = config_properties.getProperty("portnumber", port); 
    209         host = config_properties.getProperty("host", host); 
    210  
     211         
     212        // The "hosts" property in the config file contains more than one allowed host 
     213        // Need to work out the particular host chosen from the address_resolution_method 
     214        // Default is address_resolution_method 2: localhost 
     215        String addressResolutionMethod = config_properties.getProperty("address_resolution_method"); 
     216        int address_resolution_method = (addressResolutionMethod == null) ? 2 : Integer.parseInt(addressResolutionMethod); 
     217        InetAddress inetAddress = null; 
     218        try { 
     219        inetAddress = InetAddress.getLocalHost(); 
     220        } catch(UnknownHostException e) { 
     221        logger_.error(e); 
     222        logger_.info("Defaulting host IP to "+ host); // use the default         
     223        address_resolution_method = 2; 
     224        } 
     225        switch(address_resolution_method) { 
     226        case 0: 
     227        host = inetAddress.getHostName(); 
     228        break; 
     229        case 1: 
     230        host = inetAddress.getHostAddress(); 
     231        break; 
     232        case 2: 
     233        host = "localhost"; 
     234        break; 
     235        case 3: 
     236        host = "127.0.0.1"; 
     237        break; 
     238        default: 
     239        host = "localhost";          
     240        } 
    211241    } catch(Exception e) { 
    212242        recordError("Exception trying to load properties from gsdlsite_cfg. Using default library prefix.", e); 
  • greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java

    r20604 r20618  
    1313import org.greenstone.server.BaseServerSettings; 
    1414 
    15 public class Server2Settings extends BaseServerSettings implements ActionListener 
     15public class Server2Settings extends BaseServerSettings 
    1616{ 
    1717    protected JComboBox prefix_combobox; 
     
    4141    allowConnections = new JCheckBox(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".ExternalAccess"), allowCons); 
    4242    allowConnections.setBackground(bg_color); 
    43     allowConnections.addActionListener(this); 
    4443     
    4544    JPanel connect_panel = new JPanel(new GridLayout(4, 1)); 
    4645    connect_panel.setBackground(bg_color); 
    47     connect_panel.setBorder(BorderFactory.createTitledBorder("Connection configuration")); 
     46    connect_panel.setBorder(BorderFactory.createTitledBorder(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AddressResolutionMethod"))); 
    4847 
    4948    hostRadioButtons = new JRadioButton[4]; 
     
    5857        hostGroup.add(hostRadioButtons[i]); 
    5958        hostRadioButtons[i].setBackground(bg_color); 
    60         hostRadioButtons[i].setEnabled(!allowCons); 
    61     } 
    62      
     59    }    
    6360 
    6461    String addressResolutionMethod = server.config_properties.getProperty("address_resolution_method").trim(); 
     
    114111     
    115112    // work out the host (default is address_resolution_method 2: localhost) 
    116     String host = "localhost"; 
     113    String hosts = "127.0.0.1 localhost"; 
     114    String fixedHostIP = "127.0.0.1"; 
    117115    InetAddress inetAddress = null; 
    118116    try { 
    119117        inetAddress = InetAddress.getLocalHost(); 
     118 
     119        fixedHostIP = inetAddress.getHostAddress(); // used for all cases unless things go wrong 
     120        hosts = "127.0.0.1 " + fixedHostIP;         // for address_resolution_methods 1 and 3 
     121 
     122        if(address_resolution_method == 2) { 
     123        hosts = hosts + " localhost"; 
     124        } else if(address_resolution_method == 0) { 
     125        hosts = hosts + " " + inetAddress.getHostName() + " localhost"; 
     126        } 
    120127    } catch(UnknownHostException e) { 
    121128        logger.error(e); 
    122         logger.info("Server2.java reload(): Defaulting host IP to "+ host); // use the default       
     129        logger.info("Server2.java reload(): Defaulting host IP to localhost"); 
     130        fixedHostIP = "127.0.0.1"; 
    123131        address_resolution_method = 2; 
     132        hosts = "127.0.0.1 localhost"; 
    124133    } 
    125     switch(address_resolution_method) { 
    126     case 0: 
    127         host = inetAddress.getHostName(); 
    128         break; 
    129     case 1: 
    130         host = inetAddress.getHostAddress(); 
    131         break; 
    132     case 3: 
    133         host = "127.0.0.1"; 
    134         break; 
    135     case 2: default: 
    136         host = "localhost";          
    137     } 
    138     newFileLines = scriptReadWrite.queryReplace(newFileLines, "host", host); 
     134 
     135    newFileLines = scriptReadWrite.queryReplace(newFileLines, "hosts", hosts); 
     136    newFileLines = scriptReadWrite.queryReplace(newFileLines, "hostIP", fixedHostIP); 
    139137 
    140138    // address resolution method - onSave() would have updated 
     
    142140    newFileLines = scriptReadWrite.queryReplace(newFileLines, "address_resolution_method", Integer.toString(address_resolution_method)); 
    143141     
    144     } 
    145  
    146     public void actionPerformed(ActionEvent e) { 
    147     boolean toggle = !allowConnections.isSelected(); 
    148     if(e.getSource() == allowConnections) { 
    149         for(int i = 0; i < hostRadioButtons.length; i++) { 
    150         hostRadioButtons[i].setEnabled(toggle); 
    151         } 
    152     } 
    153     } 
    154  
     142    }     
    155143}