source: greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java@ 20618

Last change on this file since 20618 was 20618, checked in by ak19, 15 years ago
  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.
File size: 5.3 KB
Line 
1package org.greenstone.server;
2
3import java.awt.BorderLayout;
4import java.awt.FlowLayout;
5import java.awt.GridLayout;
6import java.awt.event.*;
7import java.net.InetAddress;
8import java.net.UnknownHostException;
9import java.util.ArrayList;
10import javax.swing.*;
11import javax.swing.event.*;
12
13import org.greenstone.server.BaseServerSettings;
14
15public class Server2Settings extends BaseServerSettings
16{
17 protected JComboBox prefix_combobox;
18 protected JCheckBox allowConnections;
19 protected JRadioButton[] hostRadioButtons = new JRadioButton[4];
20
21 // 0 to 3: 0 is resolve (hostname) from local IP, 1 is local IP address, 2 is localhost, 3 is 127.0.0.1
22 protected int address_resolution_method = 2;
23 protected int externalaccess = 0;
24
25 public Server2Settings(BaseServer server)
26 {
27 super(server);
28 }
29
30 protected JPanel createServletPanel()
31 {
32 JPanel server2panel = new JPanel();
33 server2panel.setLayout(new BorderLayout());
34
35 boolean allowCons = false;
36 String externalAccess = server.config_properties.getProperty("externalaccess").trim();
37 if(externalAccess != null && externalAccess.equals("1")) {
38 this.externalaccess = 1;
39 allowCons = true;
40 }
41 allowConnections = new JCheckBox(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".ExternalAccess"), allowCons);
42 allowConnections.setBackground(bg_color);
43
44 JPanel connect_panel = new JPanel(new GridLayout(4, 1));
45 connect_panel.setBackground(bg_color);
46 connect_panel.setBorder(BorderFactory.createTitledBorder(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AddressResolutionMethod")));
47
48 hostRadioButtons = new JRadioButton[4];
49 hostRadioButtons[0] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".ResolveIP"));
50 hostRadioButtons[1] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".LocalIP"));
51 hostRadioButtons[2] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AlwaysUse")+" localhost");
52 hostRadioButtons[3] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AlwaysUse")+" 127.0.0.1");
53
54 ButtonGroup hostGroup = new ButtonGroup();
55 for(int i = 0; i < hostRadioButtons.length; i ++) {
56 connect_panel.add(hostRadioButtons[i]);
57 hostGroup.add(hostRadioButtons[i]);
58 hostRadioButtons[i].setBackground(bg_color);
59 }
60
61 String addressResolutionMethod = server.config_properties.getProperty("address_resolution_method").trim();
62 if(addressResolutionMethod != null) {
63 this.address_resolution_method = Integer.parseInt(addressResolutionMethod);
64 }
65 hostRadioButtons[address_resolution_method].setSelected(true);
66
67 JPanel comb_panel = new JPanel(new BorderLayout());
68 comb_panel.add(allowConnections, BorderLayout.NORTH);
69 comb_panel.add(connect_panel, BorderLayout.CENTER);
70 return comb_panel;
71 }
72
73 public boolean[] onSave()
74 {
75 // superclass detects changes to port and autoenter
76 // handle changes to address_resolution_method and externalAccess/allowConnections here
77
78 boolean hasChanged = false;
79 boolean requireRestart = false;
80
81 for(int i = 0; i < hostRadioButtons.length; i++) {
82 if(hostRadioButtons[i].isSelected() && address_resolution_method != i) {
83 address_resolution_method = i;
84 hasChanged = true;
85 requireRestart = true;
86 }
87 }
88
89 int oldExternalAccess = externalaccess;
90 externalaccess = allowConnections.isSelected() ? 1 : 0;
91 if (oldExternalAccess != externalaccess) {
92 hasChanged = true;
93 requireRestart = true;
94 }
95
96 boolean[] returnValues = { hasChanged, requireRestart };
97 return returnValues;
98 }
99
100 public void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines)
101 {
102 // write only 1 or 0 (and not true or false) for Server2
103 boolean auto_enter = autoEnter.isSelected();
104 if(autoStart != auto_enter) {
105 String newAutoEnter = auto_enter ? "1" : "0";
106 newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter);
107 }
108
109 // external access - onSave() would have updated this value
110 newFileLines = scriptReadWrite.queryReplace(newFileLines, "externalaccess", Integer.toString(externalaccess));
111
112 // work out the host (default is address_resolution_method 2: localhost)
113 String hosts = "127.0.0.1 localhost";
114 String fixedHostIP = "127.0.0.1";
115 InetAddress inetAddress = null;
116 try {
117 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 }
127 } catch(UnknownHostException e) {
128 logger.error(e);
129 logger.info("Server2.java reload(): Defaulting host IP to localhost");
130 fixedHostIP = "127.0.0.1";
131 address_resolution_method = 2;
132 hosts = "127.0.0.1 localhost";
133 }
134
135 newFileLines = scriptReadWrite.queryReplace(newFileLines, "hosts", hosts);
136 newFileLines = scriptReadWrite.queryReplace(newFileLines, "hostIP", fixedHostIP);
137
138 // address resolution method - onSave() would have updated
139 // this value (or the UnknownHostException above might have)
140 newFileLines = scriptReadWrite.queryReplace(newFileLines, "address_resolution_method", Integer.toString(address_resolution_method));
141
142 }
143}
Note: See TracBrowser for help on using the repository browser.