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

Last change on this file since 23251 was 23251, checked in by sjm84, 13 years ago

The localhost and hostname did not work on the Ubuntu here, but should have been working. It does work if hostname and localhost are written into the httpd.conf file. To get it to do that, made changes to the server.jar code, and so also server.jar, as well as GS2 scripts and config files (httpd.conf.in files for linux and windows), llssite.cfg.in, glisite.cfg.in and gsicontrol.bat and .sh

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