[18558] | 1 | package org.greenstone.server;
|
---|
| 2 |
|
---|
[18710] | 3 | import java.awt.BorderLayout;
|
---|
[20604] | 4 | import java.awt.FlowLayout;
|
---|
| 5 | import java.awt.GridLayout;
|
---|
[18710] | 6 | import java.awt.event.*;
|
---|
[20604] | 7 | import java.net.InetAddress;
|
---|
| 8 | import java.net.UnknownHostException;
|
---|
[18868] | 9 | import java.util.ArrayList;
|
---|
[18558] | 10 | import javax.swing.*;
|
---|
[18710] | 11 | import javax.swing.event.*;
|
---|
[18558] | 12 |
|
---|
| 13 | import org.greenstone.server.BaseServerSettings;
|
---|
[22085] | 14 | import org.greenstone.util.ScriptReadWrite;
|
---|
[18558] | 15 |
|
---|
[20618] | 16 | public class Server2Settings extends BaseServerSettings
|
---|
[18558] | 17 | {
|
---|
[18710] | 18 | protected JComboBox prefix_combobox;
|
---|
[20604] | 19 | protected JCheckBox allowConnections;
|
---|
| 20 | protected JRadioButton[] hostRadioButtons = new JRadioButton[4];
|
---|
[18710] | 21 |
|
---|
[23251] | 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
|
---|
[20604] | 23 | protected int address_resolution_method = 2;
|
---|
| 24 | protected int externalaccess = 0;
|
---|
| 25 |
|
---|
[18558] | 26 | public Server2Settings(BaseServer server)
|
---|
| 27 | {
|
---|
[20604] | 28 | super(server);
|
---|
[18558] | 29 | }
|
---|
| 30 |
|
---|
| 31 | protected JPanel createServletPanel()
|
---|
| 32 | {
|
---|
[20604] | 33 | JPanel server2panel = new JPanel();
|
---|
| 34 | server2panel.setLayout(new BorderLayout());
|
---|
[18710] | 35 |
|
---|
[20604] | 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);
|
---|
[20618] | 47 | connect_panel.setBorder(BorderFactory.createTitledBorder(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AddressResolutionMethod")));
|
---|
[18668] | 48 |
|
---|
[20604] | 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");
|
---|
[18668] | 54 |
|
---|
[20604] | 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);
|
---|
[20618] | 60 | }
|
---|
[20604] | 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);
|
---|
[18668] | 71 | return comb_panel;
|
---|
[18558] | 72 | }
|
---|
[18710] | 73 |
|
---|
[20604] | 74 | public boolean[] onSave()
|
---|
[18710] | 75 | {
|
---|
[20604] | 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;
|
---|
[20945] | 87 | server.reconfigRequired();
|
---|
[20604] | 88 | }
|
---|
[18969] | 89 | }
|
---|
[20604] | 90 |
|
---|
| 91 | int oldExternalAccess = externalaccess;
|
---|
| 92 | externalaccess = allowConnections.isSelected() ? 1 : 0;
|
---|
| 93 | if (oldExternalAccess != externalaccess) {
|
---|
| 94 | hasChanged = true;
|
---|
| 95 | requireRestart = true;
|
---|
[20945] | 96 | server.reconfigRequired();
|
---|
[20604] | 97 | }
|
---|
| 98 |
|
---|
| 99 | boolean[] returnValues = { hasChanged, requireRestart };
|
---|
| 100 | return returnValues;
|
---|
[18710] | 101 | }
|
---|
| 102 |
|
---|
[18868] | 103 | public void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines)
|
---|
| 104 | {
|
---|
[20604] | 105 | // write only 1 or 0 (and not true or false) for Server2
|
---|
[18969] | 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 | }
|
---|
[24207] | 111 | boolean keep_port = keepPortToggle.isSelected();
|
---|
| 112 | if(keepPort != keep_port) {
|
---|
| 113 | String newKeepPort = keep_port ? "1" : "0";
|
---|
| 114 | newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.KEEPPORT, newKeepPort);
|
---|
| 115 | }
|
---|
[18868] | 116 |
|
---|
[20604] | 117 | // external access - onSave() would have updated this value
|
---|
| 118 | newFileLines = scriptReadWrite.queryReplace(newFileLines, "externalaccess", Integer.toString(externalaccess));
|
---|
| 119 |
|
---|
| 120 | // work out the host (default is address_resolution_method 2: localhost)
|
---|
[20623] | 121 | String hostIP = "127.0.0.1";
|
---|
[23251] | 122 | String hosts = "";
|
---|
[20604] | 123 | InetAddress inetAddress = null;
|
---|
| 124 | try {
|
---|
| 125 | inetAddress = InetAddress.getLocalHost();
|
---|
[23251] | 126 | hosts = inetAddress.getHostName();
|
---|
[20623] | 127 | hostIP = inetAddress.getHostAddress(); // used for all cases unless an Exception is thrown here
|
---|
[20604] | 128 | } catch(UnknownHostException e) {
|
---|
| 129 | logger.error(e);
|
---|
[20623] | 130 | logger.info("Server2.java reload(): Defaulting host URL to localhost");
|
---|
| 131 | hostIP = "127.0.0.1";
|
---|
[23251] | 132 | hosts = "";
|
---|
[20623] | 133 | address_resolution_method = 2;
|
---|
[18710] | 134 | }
|
---|
| 135 |
|
---|
[20940] | 136 | newFileLines = scriptReadWrite.replaceOrAddLine(newFileLines, "hostIP", hostIP, true);
|
---|
[23251] | 137 | newFileLines = scriptReadWrite.replaceOrAddLine(newFileLines, "hosts", hosts, true);
|
---|
[20618] | 138 |
|
---|
[20604] | 139 | // address resolution method - onSave() would have updated
|
---|
| 140 | // this value (or the UnknownHostException above might have)
|
---|
| 141 | newFileLines = scriptReadWrite.queryReplace(newFileLines, "address_resolution_method", Integer.toString(address_resolution_method));
|
---|
[18710] | 142 |
|
---|
[20618] | 143 | }
|
---|
[18558] | 144 | }
|
---|