ConfigWizard.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* This wizard configures the DHCP service. It also has a mode switch so
* that it is also usable for just adding a single network, so that in
* the tool it actually performs the Network Wizard function as well.
*/
public class ConfigWizard extends DSWizard {
private boolean fullConfig;
private DhcpServiceMgr server;
private boolean leaseNegotiable = true;
private boolean isLan = true;
private boolean routerDiscovery = true;
private String nisplusDomain;
private Vector nisplusServs;
private static final String [] unitChoices = {
/**
* This class defines a host resource component.
*/
private class HostResource extends Box {
/**
* The host resource(eg., files, nisplus, dns).
*/
/**
* The description of the resource.
*/
/**
* The button for the resource.
*/
/**
* The domain field for the resource (if any)
*/
/**
* The constructor.
* @param resource the resource value for the config file
* @param description description of the resource
* @param defaultdomain default domain (if any) for the resource
* @param enabled determines whether resource is selectable
*/
this.description = description;
// Every host resource needs a button even if the resource
// isn't one that will be selectable.
//
hostButton = new HostButton(this, false);
if (!enabled) {
hostButton.setEnabled(false);
defaultDomain = new String();
}
// If the defaultDomain is null, then the host resource
// does not require a domain. Otherwise, the resource
// must have a text field so that the user can supply
// a domain.
//
if (defaultDomain != null) {
domainField.setEnabled(false);
if (!enabled) {
domainField.setEditable(false);
label.setEnabled(false);
} else {
// Disable the forward button if domain empty.
public void insertUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
};
}
}
} // constructor
/**
* Sets or unsets the host resource.
* @param isSelected if true, sets the resource, else unsets it
*/
public void setSelected(boolean isSelected) {
if (isSelected) {
setHostResource(this);
if (!hostButton.isSelected()) {
hostButton.setSelected(true);
}
if (domainField != null) {
domainField.setEnabled(true);
} else {
setForwardEnabled(true);
}
} else {
if (domainField != null) {
domainField.setEnabled(false);
}
}
} // setSelected
/**
* Returns the host resource.
* @return the host resource.
*/
public String getResource() {
return resource;
} // getResource
/**
* Returns the resource description.
* @return the resource description.
*/
public String getDescription() {
return description;
} // getDescription
/**
* Returns the domain for this component.
* @return the domain for this component.
*/
if (domainField == null) {
return null;
} else {
return domainField.getText();
}
} // getDomain
/**
* Returns the HostButton contained in this component.
* @return the HostButton contained in this component.
*/
public HostButton getHostButton() {
return hostButton;
} // getHostButton
} // hostResource
/**
* This class maps a radio button to its HostResource
*/
private class HostButton extends JRadioButton {
/**
* The HostResource to link to the radio button.
*/
/**
* Constructs a HostButton from a HostResource and determines
* whether the button should be selected using the boolean argument.
* @param hostResource the HostResource to map to the radio button.
* @param selected select the radio button?
*/
this.hostResource = hostResource;
} // constructor
/**
* Returns the HostResource mapped to the radio button.
* @return the HostResource mapped to the radio button.
*/
public HostResource getHostResource() {
return hostResource;
} // getHostResource
} // HostButton
// Select where host data will be stored.
class HostDataStep implements WizardStep {
/**
* The component provided to the wizard.
*/
/**
* The basic constructor for the wizard step.
*/
public HostDataStep() {
// Explanatory step text
//
// Create button listener, that will set the selected
// host resource when the button is selected.
//
public void stateChanged(ChangeEvent e) {
}
};
// Create panel that will contain the buttons.
//
// List the host resource choices.
//
// The "do not manage hosts" option.
//
hostResource.setSelected(true);
// The "files" option.
//
// The "nisplus" option. Only enabled if it can be managed
// from the selected server.
//
boolean enabled = false;
try {
// If we can obtain a server list, then nisplus is enabled.
enabled = true;
} catch (Throwable e) {
domainDefault = new String();
}
// The "dns" option. Only enabled if it can be managed
// from the selected server.
//
try {
} catch (Throwable e) {
domainDefault = new String();
}
try {
enabled =
} catch (Throwable e) {
enabled = false;
}
// Add the panel to the stepBox component.
//
} // constructor
public String getDescription() {
} // getDescription
public Component getComponent() {
return stepBox;
} // getComponent
setForwardEnabled(true);
} // setActive
public boolean setInactive(int direction) {
// input by the user is manageable from the selected server.
//
boolean valid = true;
try {
} catch (Throwable e) {
valid = false;
}
}
if (!valid) {
}
}
return (valid);
} // setInactive
} // HostDataStep
// This step specifies lease length and renewal policies for the server
class LeaseStep implements WizardStep {
private IntegerField length;
private JCheckBox negotiable;
public LeaseStep() {
// Explanatory text
// Need to input a number together with units
// Use a box for the value and units to keep together in layout
length = new IntegerField();
// Explain negotiable, provide selection for it
45));
negotiable = new JCheckBox(
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
// Set the units field to the maximum unit this value expresses
int lengthVal = 0;
int i;
if (lengthVal != 0) {
break;
}
}
}
if (i == -1) {
i = 0;
}
}
public boolean setInactive(int direction) {
// Leases cannot be zero length
if (lease == 0) {
return false;
}
lease *= multiplier;
// Value is too large
};
return false;
}
leaseLength = (int)lease;
return true;
}
}
// Step to configure DNS
class DnsStep implements WizardStep {
private NoSpaceField domain;
private IPAddressList serverList;
private boolean firstActive = true;
public DnsStep() {
// Explanatory text
// Domain first
domain = new NoSpaceField();
serverList = new IPAddressList();
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
// First time through, ask the server for the defaults
if (firstActive) {
firstActive = false;
try {
""));
} catch (Throwable e) {
// Ignore errors, we're just supplying defaults
}
}
}
public boolean setInactive(int direction) {
/*
* Either must supply both a domain and a list of servers, or
* neither
*/
return false;
}
}
return true;
}
}
// Select the network to configure
class NetworkStep implements WizardStep {
private JComboBox networkBox;
private NetworkListModel networkListModel;
private IPAddressField mask;
private boolean firstActive = true;
// Model for the list of networks
class NetworkListModel extends AbstractListModel
implements ComboBoxModel {
private Object currentValue;
public int getSize() {
return 0;
} else {
}
}
return null;
} else {
}
}
}
public Object getSelectedItem() {
return currentValue;
}
}
}
/*
* Editor for the Network combo box, ensures that a valid IP address
* is entered. This implementation cribbed from Swing's
*/
private IPAddressField editor;
public NetworkComboBoxEditor() {
editor = new IPAddressField();
editor.addFocusListener(this);
}
public Component getEditorComponent() {
return editor;
}
} else {
}
}
}
public void selectAll() {
}
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
}
public void addActionListener(ActionListener l) {
}
public void removeActionListener(ActionListener l) {
}
}
public NetworkStep() {
// Start with intro text, depending on mode.
if (fullConfig) {
45));
} else {
}
networkListModel = new NetworkListModel();
networkBox.setEditable(true);
// Label and text field for subnet mask
mask = new IPAddressField();
if (fullConfig) {
45));
}
/*
* Listen to selection changes on the network box and change the
* netmask accordingly.
*/
public void itemStateChanged(ItemEvent e) {
if (a != null) {
// We know the correct value, so set it
}
}
}
});
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
if (firstActive) {
firstActive = false;
try {
/*
* Initialize list to all networks directly attached to
* the server
*/
try {
} catch (BridgeException e) {
// we're not configured yet, apparently
}
// Get list of already-configured networks
try {
} catch (BridgeException e) {
// Ignore; we're not configured yet, apparently
}
/*
* Now filter the list so only unconfigured networks
* show up in the selection list.
*/
boolean alreadyConfigured = false;
alreadyConfigured = true;
break;
}
}
if (!alreadyConfigured) {
// Add to list
addrs.addElement(s);
// Save netmask for retrieval later
}
}
}
}
} catch (Throwable e) {
// Do nothing, we're just setting defaults
e.printStackTrace();
}
}
}
public boolean setInactive(int direction) {
try {
/*
* Check for empty, in which case we just let the
* default happen
*/
// Not a valid subnet mask
return false;
}
} else {
}
// Check for network already configured, error if so
try {
} catch (BridgeException e) {
// Ignore; must not be configured yet
}
"cfg_wiz_network_configured"));
return false;
}
}
} catch (ValidationException e) {
// Not a valid IP address
}
return false;
} catch (Throwable e) {
e.printStackTrace();
// Ignore other exceptions
}
}
return true;
}
}
// Get the type of network and routing policy
class NetTypeStep implements WizardStep {
private IPAddressField address;
private boolean firstTime = true;
public NetTypeStep() {
// Explanatory text at the top
// Label and radio buttons for type of network
/*
* Create a compound border with empty space on the outside and
* a line border on the inside, then title it amd put a space
* around the outside.
*/
true);
typeGroup = new ButtonGroup();
false);
// Routing policy
discover = new JRadioButton(
"cfg_wiz_router_discovery"));
routingGroup = new ButtonGroup();
specify = new JRadioButton(
"cfg_wiz_router_specify"));
address = new IPAddressField();
// Box is sensitive to alignment, make sure they all agree
/*
* Enable forward if router discovery, or if specifying router and
* address is not empty.
*/
public void stateChanged(ChangeEvent e) {
}
});
// Enable forward when address is not empty.
public void insertUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
}
public boolean setInactive(int direction) {
if (!routerDiscovery) {
// Invalid IP address
"cfg_wiz_router_addr_err"));
return false;
// Router is not on the network we're configuring
"cfg_wiz_router_net_err"));
return false;
}
}
}
return true;
}
}
// Get the NIS configuration
class NisStep implements WizardStep {
private NoSpaceField domain;
private IPAddressField address;
private IPAddressList serverList;
boolean firstActive = true;
public NisStep() {
domain = new NoSpaceField();
serverList = new IPAddressList();
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
if (firstActive) {
firstActive = false;
try {
/*
* Order here is important; do the servers first because if
* there's an error, we don't retrieve a domain name, which
* appears to never fail.
*/
""));
} catch (Throwable e) {
// Do nothing, just setting defaults
}
}
}
public boolean setInactive(int direction) {
/*
* Either must supply both a domain and a list of servers, or
* neither
*/
return false;
}
}
return true;
}
}
// Get the NIS+ configuration
class NisplusStep implements WizardStep {
private NoSpaceField domain;
private IPAddressList serverList;
boolean firstActive = true;
public NisplusStep() {
"cfg_wiz_nisplus_domain"));
domain = new NoSpaceField();
serverList = new IPAddressList();
}
public String getDescription() {
}
public Component getComponent() {
return stepBox;
}
setForwardEnabled(true);
if (firstActive) {
firstActive = false;
try {
/*
* Order is important; the domain will always be returned
* even if NIS+ is not configured, so try finding a server
* first and if that fails we will end up with both fields
* empty.
*/
""));
} catch (Throwable e) {
// Do nothing, just setting defaults
}
}
}
public boolean setInactive(int direction) {
/*
* Either must supply both a domain and a list of servers,
* or neither
*/
return false;
}
}
return true;
}
}
class ReviewStep implements WizardStep {
private JLabel storeLabel;
private JLabel leaseLabel;
private JLabel networkLabel;
private JLabel netTypeLabel;
private JLabel netmaskLabel;
private JLabel routerLabel;
private JLabel dnsServLabel;
private JLabel nisServLabel;
private JLabel nisplusLabel;
private JLabel nisplusServLabel;
private JScrollPane scrollPane;
public ReviewStep() {
if (fullConfig) {
45));
} else {
45));
}
if (fullConfig) {
addLabel("cfg_wiz_datastore");
addLabel("cfg_wiz_hosts_resource");
addLabel("cfg_wiz_dns_servers");
}
addLabel("cfg_wiz_nettype");
addLabel("cfg_wiz_router");
addLabel("cfg_wiz_nis_servers");
addLabel("cfg_wiz_nisplus_servers");
}
}
return jl;
}
l.setLabelFor(panel);
l.setToolTipText(s);
return l;
}
public String getDescription() {
}
public Component getComponent() {
return scrollPane;
}
StringBuffer b = new StringBuffer();
setFinishEnabled(true);
if (fullConfig) {
// Display lease length, reducing to largest units possible
int lengthVal = 0;
int i;
if ((lengthVal != 0)
break;
}
}
if (i == -1) {
i = 0;
}
if (leaseNegotiable) {
} else {
}
// Set DNS info
b.setLength(0);
while (en.hasMoreElements()) {
if (b.length() != 0) {
b.append(", ");
}
b.append(a.getHostAddress());
}
}
// Set network address
// Set subnet mask
// Set network type
if (isLan) {
} else {
}
// Set router
if (routerDiscovery) {
} else {
}
// Set NIS info
b.setLength(0);
while (en.hasMoreElements()) {
if (b.length() != 0) {
b.append(", ");
}
b.append(a.getHostAddress());
}
// Set NIS+ info
b.setLength(0);
while (en.hasMoreElements()) {
if (b.length() != 0) {
b.append(", ");
}
b.append(a.getHostAddress());
}
}
public boolean setInactive(int direction) {
return true;
}
}
try {
if (fullConfig) {
dsconfList = new DSConfList();
}
} catch (Throwable e) {
e.printStackTrace(); // XXX Need to do something to handle this...
return;
}
this.fullConfig = fullConfig;
// If running as Config Wizard, put in the initial steps.
if (fullConfig) {
addStep(new DatastoreStep(
addStep(new DatastoreModuleStep());
addStep(new HostDataStep());
}
// Now the steps that are common to both wizards.
addStep(new NetworkStep());
addStep(new NetTypeStep());
addStep(new NisplusStep());
addStep(new ReviewStep());
}
public void doFinish() {
/*
* To activate the server, we have to do the following items:
* 2. Create the defaults file.
* 3. Create the dhcptab; ignore errors if it already exists
* (as in NIS+ case)
* 4. Create the Locale macro; ignore the error if it already exists
* 5. Create the server macro; if it exists we just overwrite it
* 6. Create the network macro;
* 7. Create the network table
* 8. Start the service
*/
if (fullConfig) {
getDsconf().setLocation();
try {
} catch (ExistsException e) {
// this is o.k.
} catch (Throwable e) {
msg,
return;
}
// Create the defaults file.
options.setDaemonEnabled(true);
}
}
try {
} catch (Throwable e) {
e.printStackTrace();
return;
}
// Create the dhcptab
try {
} catch (Throwable e) {
// Not an error; some data stores are shared by multiple servers
}
}
if (fullConfig) {
try {
} catch (Throwable e) {
/*
* Ignore this error, if one's already there we'll assume
* it's correct
*/
}
// Create the Server macro
try {
dnsServs);
} catch (Throwable e) {
// Couldn't create it; inform user because this is serious
return;
}
}
// Create the network macro
}
try {
} catch (Throwable e) {
// Ignore this error? dhcpconfig gives a merge option
}
// Create the network table
try {
} catch (BridgeException e) {
// This indicates table existed; no error
} catch (Throwable e) {
return;
}
// Start the server in the initial configuration case
if (fullConfig) {
try {
} catch (Throwable e) {
// Just warn user; this isn't disastrous
}
}
super.doFinish();
}
public void doHelp() {
if (fullConfig) {
} else {
}
}
/**
* Sets hostResource.
* @param hostResource the host resource value.
*/
this.hostResource = hostResource;
} // setHostResource
/**
* Returns the hostResource.
* @return the hostResource.
*/
public HostResource getHostResource() {
return hostResource;
} // getHostResource
}