Index: /greenstone3/trunk/src/java/org/greenstone/server/BaseServerSettings.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/server/BaseServerSettings.java	(revision 20603)
+++ /greenstone3/trunk/src/java/org/greenstone/server/BaseServerSettings.java	(revision 20604)
@@ -26,5 +26,5 @@
     protected Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
 
-    static final private Dimension SIZE = new Dimension(300, 350);
+    static final private Dimension SIZE = new Dimension(300, 450);
     static final Color bg_color = Color.white; 
 
@@ -111,17 +111,15 @@
 	port_panel.setBackground(bg_color);
 
+	JPanel top_panel = new JPanel(new GridLayout(2,1));
+	top_panel.add(port_panel);
+	top_panel.add(autoEnter);
+
 	JPanel comb_panel = createServletPanel();
 	comb_panel.setBackground(bg_color);
-        
-	JPanel check_panel = new JPanel(); 
-       	check_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
-        check_panel.add(autoEnter);
-        check_panel.setBackground(bg_color);
 
 	JPanel mid_panel = new JPanel();
-        mid_panel.setLayout(new GridLayout(3,1));
-	mid_panel.add(port_panel);
-	mid_panel.add(check_panel);
-	mid_panel.add(comb_panel);
+	mid_panel.setLayout(new BorderLayout());
+	mid_panel.add(top_panel, BorderLayout.NORTH);
+	mid_panel.add(comb_panel, BorderLayout.CENTER);
 	mid_panel.setBackground(bg_color);
 	mid_panel.setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
@@ -181,5 +179,8 @@
 
 
-    protected String onSave() { return ""; }
+    protected boolean[] onSave() {
+	boolean[] returnValues = { false, false }; // hasChanged, requireRestart
+	return returnValues;
+    }
     protected void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines) {}
     protected abstract JPanel createServletPanel();
@@ -223,9 +224,10 @@
 	public void actionPerformed(ActionEvent ev) {
 	    // save everything to config_properties if things have changed
-	     boolean has_changed = false;
-             boolean require_restart = false;
+	    boolean has_changed = false;
+            boolean require_restart = false;
+
 	    if (portNum != ((Integer)portNumber_spinner.getValue()).intValue()) {
 		has_changed = true;
-                require_restart = true; 
+                require_restart = true;
                 server.reconfigRequired();
                 portNum = ((Integer)portNumber_spinner.getValue()).intValue();
@@ -236,12 +238,9 @@
 	    }
 
-	    // call subclass' onSave method
-	    String result = onSave();
-	    if(result.indexOf("changed") != -1) {
-		has_changed = true;
-	    }
-	    if(result.indexOf("restart") != -1) {
-		require_restart = true;
-	    }
+	    // call subclass' onSave method, which may indicate (further) changes,
+	    // and which may or may not require a restart
+	    boolean[] returnValues = onSave();
+	    has_changed = has_changed || returnValues[0];
+	    require_restart = require_restart || returnValues[1];
 
             //changed to use other browser
@@ -251,11 +250,11 @@
 	    } 
 	    //the browser path has been changed 
-	    if ( !useDefaultBrowser && !browserPath.equals(program_path_field.getText())){
+	    if (!useDefaultBrowser && !browserPath.equals(program_path_field.getText())){
 		browserPath = program_path_field.getText();
-		 has_changed = true;
+		has_changed = true;
 	    }
 	    
             //changed to use the default browser
-	    if ( default_browser_button.isSelected() && !useDefaultBrowser){
+	    if (default_browser_button.isSelected() && !useDefaultBrowser){
 		browserPath = "";
 		has_changed = true;
@@ -286,5 +285,5 @@
 		server.reload(); // work out the URL again in case it has changed
 		if (require_restart){
-		    JOptionPane.showMessageDialog(null,server.dictionary.get("ServerSetting.SettingChanged"),"Info", JOptionPane.INFORMATION_MESSAGE);
+		    JOptionPane.showMessageDialog(null,server.dictionary.get("ServerSettings.SettingChanged"),"Info", JOptionPane.INFORMATION_MESSAGE);
 		    if(autoStart) {
 			server.autoStart();
Index: /greenstone3/trunk/src/java/org/greenstone/server/Server2.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/server/Server2.java	(revision 20603)
+++ /greenstone3/trunk/src/java/org/greenstone/server/Server2.java	(revision 20604)
@@ -186,6 +186,5 @@
 	String suffix = "/cgi-bin/library.cgi";
 
-	// get the prefix from the gsdlsite.cfg and build.properties files
-	// (port number and servername)
+	// get the prefix from the gsdlsite.cfg and build.properties files (port number and servername)
 	try{
 	    File gsdlsite_cfg = new File(gsdl_home + File.separator + "cgi-bin" + File.separator + "gsdlsite.cfg");
@@ -208,4 +207,6 @@
 	    //reloadConfigProperties();
 	    port = config_properties.getProperty("portnumber", port);
+	    host = config_properties.getProperty("host", host);
+
 	} catch(Exception e) {
 	    recordError("Exception trying to load properties from gsdlsite_cfg. Using default library prefix.", e);
Index: /greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java	(revision 20603)
+++ /greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java	(revision 20604)
@@ -2,5 +2,9 @@
 
 import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.awt.GridLayout;
 import java.awt.event.*;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import javax.swing.*;
@@ -9,43 +13,95 @@
 import org.greenstone.server.BaseServerSettings;
 
-public class Server2Settings extends BaseServerSettings implements ChangeListener, ActionListener
+public class Server2Settings extends BaseServerSettings implements ActionListener
 {
     protected JComboBox prefix_combobox;
+    protected JCheckBox allowConnections;
+    protected JRadioButton[] hostRadioButtons = new JRadioButton[4];
+
+    // 0 to 3: 0 is resolve (hostname) from local IP, 1 is local IP address, 2 is localhost, 3 is 127.0.0.1
+    protected int address_resolution_method = 2;
+    protected int externalaccess = 0;
 
     public Server2Settings(BaseServer server) 
     {
-	super(server);
+	super(server);	
     }
 
     protected JPanel createServletPanel()
     {
-	portNumber_spinner.addChangeListener(this);
+	JPanel server2panel = new JPanel();
+	server2panel.setLayout(new BorderLayout());
 
-	JLabel prefix_label = new JLabel(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".URL"));
+	boolean allowCons = false;
+	String externalAccess = server.config_properties.getProperty("externalaccess").trim();
+	if(externalAccess != null && externalAccess.equals("1")) {
+	    this.externalaccess = 1;
+	    allowCons = true;
+	}
+	allowConnections = new JCheckBox(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".ExternalAccess"), allowCons);
+	allowConnections.setBackground(bg_color);
+	allowConnections.addActionListener(this);
+	
+	JPanel connect_panel = new JPanel(new GridLayout(4, 1));
+	connect_panel.setBackground(bg_color);
+	connect_panel.setBorder(BorderFactory.createTitledBorder("Connection configuration"));
 
-	prefix_combobox = new JComboBox();
-	prefix_combobox.setEditable(true);
-	prefix_combobox.addItem(server.getBrowserURL());
-	prefix_combobox.addActionListener(this);
+	hostRadioButtons = new JRadioButton[4];
+	hostRadioButtons[0] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".ResolveIP"));
+	hostRadioButtons[1] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".LocalIP"));
+	hostRadioButtons[2] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AlwaysUse")+" localhost");
+	hostRadioButtons[3] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AlwaysUse")+" 127.0.0.1");
 
-	JPanel comb_panel = new JPanel();
-	comb_panel.setLayout(new BorderLayout());
-	comb_panel.add(prefix_label, BorderLayout.NORTH);
-	comb_panel.add(prefix_combobox, BorderLayout.CENTER);
+	ButtonGroup hostGroup = new ButtonGroup();
+	for(int i = 0; i < hostRadioButtons.length; i ++) {
+	    connect_panel.add(hostRadioButtons[i]);
+	    hostGroup.add(hostRadioButtons[i]);
+	    hostRadioButtons[i].setBackground(bg_color);
+	    hostRadioButtons[i].setEnabled(!allowCons);
+	}
+	
+
+	String addressResolutionMethod = server.config_properties.getProperty("address_resolution_method").trim();
+	if(addressResolutionMethod != null) {
+	    this.address_resolution_method = Integer.parseInt(addressResolutionMethod);
+	}
+	hostRadioButtons[address_resolution_method].setSelected(true);
+
+	JPanel comb_panel = new JPanel(new BorderLayout());	
+	comb_panel.add(allowConnections, BorderLayout.NORTH);
+	comb_panel.add(connect_panel, BorderLayout.CENTER);
 	return comb_panel;
     }
 
-    public String onSave() 
+    public boolean[] onSave()
     {
-	String result = "";
-	if (!server.getBrowserURL().equals(prefix_combobox.getSelectedItem())) {
-	    result += "changed";
-	    result += "restart";
+	// superclass detects changes to port and autoenter
+	// handle changes to address_resolution_method and externalAccess/allowConnections here
+
+	boolean hasChanged = false;
+	boolean requireRestart = false;
+	
+	for(int i = 0; i < hostRadioButtons.length; i++) {
+	    if(hostRadioButtons[i].isSelected() && address_resolution_method != i) {
+		address_resolution_method = i;
+		hasChanged = true;
+		requireRestart = true;
+	    }
 	}
-	return result;
+
+	int oldExternalAccess = externalaccess;
+	externalaccess = allowConnections.isSelected() ? 1 : 0;
+	if (oldExternalAccess != externalaccess) {
+	    hasChanged = true;
+	    requireRestart = true;
+	}
+
+	boolean[] returnValues = { hasChanged, requireRestart };
+	return returnValues;
     }
 
     public void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines) 
     {
+	// write only 1 or 0 (and not true or false) for Server2
 	boolean auto_enter = autoEnter.isSelected();
 	if(autoStart != auto_enter) {
@@ -53,58 +109,45 @@
 	    newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter);
 	}
-    }
 
-    public void stateChanged(ChangeEvent e) {
-	int portNumber = ((Integer)portNumber_spinner.getValue()).intValue();
-	String url = (String)prefix_combobox.getSelectedItem();
-	url.replace('\\', '/');
-	String pre = "";
-	if(url.indexOf("http://") != -1) {
-	    pre = "http://";
-	    url = url.substring(7);
+	// external access - onSave() would have updated this value
+	newFileLines = scriptReadWrite.queryReplace(newFileLines, "externalaccess", Integer.toString(externalaccess));
+	
+	// work out the host (default is address_resolution_method 2: localhost)
+	String host = "localhost";
+	InetAddress inetAddress = null;
+	try {
+	    inetAddress = InetAddress.getLocalHost();
+	} catch(UnknownHostException e) {
+	    logger.error(e);
+	    logger.info("Server2.java reload(): Defaulting host IP to "+ host); // use the default		
+	    address_resolution_method = 2;
 	}
+	switch(address_resolution_method) {
+	case 0:
+	    host = inetAddress.getHostName();
+	    break;
+	case 1:
+	    host = inetAddress.getHostAddress();
+	    break;
+	case 3:
+	    host = "127.0.0.1";
+	    break;
+	case 2: default:
+	    host = "localhost";		    
+	}
+	newFileLines = scriptReadWrite.queryReplace(newFileLines, "host", host);
 
-	String[] parts = url.split("/");
-	String prefix = parts[0];
-
-	int colon = prefix.indexOf(':');
-	if(colon != -1) {
-	    prefix = prefix.substring(0, colon);
-	} 
+	// address resolution method - onSave() would have updated
+	// this value (or the UnknownHostException above might have)
+	newFileLines = scriptReadWrite.queryReplace(newFileLines, "address_resolution_method", Integer.toString(address_resolution_method));
 	
-	url = pre + prefix + ":" + portNumber;
-	for(int i = 1; i < parts.length; i++) {
-	    url = url + "/" + parts[i];
-	}
-
-	prefix_combobox.setSelectedItem(url);	
     }
 
     public void actionPerformed(ActionEvent e) {
-	String url = (String)prefix_combobox.getSelectedItem();
-	int portNumber = 80;
-
-	String oldUrl = url;
-	if(url.indexOf("http://") != -1) {
-	    url = url.substring(7);
-	}
-	int colon = url.indexOf(':');
-	int slash = url.indexOf('/');
-	if(slash == -1) {
-	    slash = url.length();
-	}
-	if(colon != -1) {
-	    url = url.substring(colon+1, slash);
-	    try { 
-		portNumber_spinner.setValue(Integer.decode(url));
-	    } catch(NumberFormatException nfe) { // couldn't parse port number
-		// not an integer, leave portnumber at 80
-		String oldNum = portNumber_spinner.getValue().toString();
-		oldUrl = oldUrl.replaceFirst(oldNum, "80");
-		portNumber_spinner.setValue(new Integer(80));
+	boolean toggle = !allowConnections.isSelected();
+	if(e.getSource() == allowConnections) {
+	    for(int i = 0; i < hostRadioButtons.length; i++) {
+		hostRadioButtons[i].setEnabled(toggle);
 	    }
-	} else { // no port number
-	    oldUrl = oldUrl.replaceFirst(url, url+":80");
-	    portNumber_spinner.setValue(new Integer(80));
 	}
     }
Index: /greenstone3/trunk/src/java/org/greenstone/server/Server3Settings.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/server/Server3Settings.java	(revision 20603)
+++ /greenstone3/trunk/src/java/org/greenstone/server/Server3Settings.java	(revision 20604)
@@ -74,12 +74,14 @@
     }
 
-    public String onSave() 
+    public boolean[] onSave()
     {
-	String result = "";
+	boolean hasChanged = false;
+	boolean requireRestart = false;
 	if (!servletDefault.equals((String)url_mappings.get(servlet_combobox.getSelectedItem()))) {
-	    result += "changed";
-	    result += "restart";
+	    hasChanged = true;
+	    requireRestart = true;
 	}
-	return result;
+	boolean[] returnValues = { hasChanged, requireRestart };
+	return returnValues;
     }
 
