1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23 /*
24 * ident "%Z%%M% %I% %E% SMI"
25 *
26 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29 package com.sun.dhcpmgr.client;
30
31 import javax.swing.*;
32 import javax.swing.border.*;
33 import javax.swing.event.*;
34 import javax.swing.table.*;
35
36 import java.awt.*;
37 import java.awt.event.*;
38 import java.text.*;
39 import java.util.*;
40
41 import com.sun.dhcpmgr.server.*;
42 import com.sun.dhcpmgr.data.*;
43 import com.sun.dhcpmgr.ui.*;
44 import com.sun.dhcpmgr.bridge.BridgeException;
45
46 /**
47 * Dialog to edit the options for the server as stored in the startup script.
48 */
49 public class ServerOptionsDialog extends DhcpmgrDialog {
50 private static int DEFAULT_RESCAN_INTERVAL = 60;
51 private DhcpdOptions options, originalOptions;
52 private JCheckBox verboseLogging, detectDuplicates, restartServer,
53 logTransactions, reloadEnabled, owneripEnabled, dnsUpdateEnabled;
54 private IntegerField relayHops, reloadInterval, cacheTime, dnsTimeout;
55 private JRadioButton noBootp, autoBootp, manualBootp;
56 private IPAddressList serverList;
57 private IPAddressList owneripList;
58 private JComboBox logFacility;
59 private JTable monitoredTable, ignoredTable;
60 private LeftButton leftButton;
61 private RightButton rightButton;
62
63 /*
64 * Model for the tables which are used to edit the lists of
65 * interfaces which are monitored and ignored.
66 */
67 class InterfaceTableModel extends AbstractTableModel {
68 private Vector interfaces;
69
70 public InterfaceTableModel() {
71 interfaces = new Vector();
72 }
73
74 // Initialize the list of interfaces
75 public void setInterfaceList(IPInterface [] ifs) {
76 interfaces.removeAllElements();
77 if (ifs != null) {
78 for (int i = 0; i < ifs.length; ++i) {
79 interfaces.addElement(ifs[i]);
80 }
81 }
82 fireTableDataChanged();
83 }
84
85 // Retrieve the interfacess as a comma-separated list
86 public String getInterfaceList() {
87 StringBuffer b = new StringBuffer();
88 Enumeration e = interfaces.elements();
89 while (e.hasMoreElements()) {
90 if (b.length() != 0) {
91 b.append(',');
92 }
93 IPInterface ipif = (IPInterface)e.nextElement();
94 b.append(ipif.getName());
95 }
96 return b.toString();
97 }
98
99 // Retrieve interface object for named interface
100 public IPInterface getInterface(String name) {
101 Enumeration e = interfaces.elements();
102 while (e.hasMoreElements()) {
103 IPInterface ipif = (IPInterface)e.nextElement();
104 if (name.equals(ipif.getName())) {
105 return ipif;
106 }
107 }
108 return null;
109 }
110
111 // Retrieve the interface object at a particular row in the table
112 public IPInterface getInterfaceAt(int row) {
113 return (IPInterface)interfaces.elementAt(row);
114 }
115
116 // Add an interface to the table
117 public void addInterface(IPInterface ipif) {
118 interfaces.addElement(ipif);
119 fireTableDataChanged();
120 }
121
122 // Delete an interface from the table
123 public void deleteInterface(IPInterface ipif) {
124 interfaces.removeElement(ipif);
125 fireTableDataChanged();
126 }
127
128 // Return number of rows
129 public int getRowCount() {
130 return interfaces.size();
131 }
132
133 // Always two columns: interface name and network
134 public int getColumnCount() {
135 return 2;
136 }
137
138 // Return cell value at a particular coordinate
139 public Object getValueAt(int row, int column) {
140 IPInterface ipif = (IPInterface)interfaces.elementAt(row);
141 if (column == 0) {
142 return ipif.getName();
143 } else {
144 return ipif.getNetwork().toString();
145 }
146 }
147
148 // All data is strings from the display's point of view
149 public Class getColumnClass(int column) {
150 return String.class;
151 }
152
153 // Get headings for each column
154 public String getColumnName(int column) {
155 if (column == 0) {
156 return ResourceStrings.getString("service_options_interface");
157 } else {
158 return ResourceStrings.getString("service_options_network");
159 }
160 }
161 }
162
163 public ServerOptionsDialog(Frame f, DhcpdOptions opts) {
164 super(f, true); // We want a reset button
165 setOptions(opts);
166 resetValues();
167 }
168
169 /**
170 * Provide a title to be displayed for the dialog
171 */
172 public String getTitle() {
173 return ResourceStrings.getString("service_options_title");
174 }
175
176 /**
177 * Construct and return the main display for this dialog.
178 */
179 protected JPanel getMainPanel() {
180
181 JPanel mainPanel = new JPanel(new BorderLayout());
182
183 /*
184 * Start with a tabbed view; the top tab is the options for the
185 * daemon, the lower tab is the interfaces to be monitored.
186 */
187 JTabbedPane tabbedPane = new JTabbedPane();
188 JPanel optionsPanel = new JPanel();
189 optionsPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
190
191 // Use a gridbag with equal weights all around, cells anchored to west
192 GridBagLayout bag = new GridBagLayout();
193 GridBagConstraints con = new GridBagConstraints();
194 con.gridx = con.gridy = 0;
195 con.weightx = con.weighty = 1.0;
196 con.anchor = GridBagConstraints.WEST;
197 con.insets = new Insets(2, 2, 2, 2);
198
199 optionsPanel.setLayout(bag);
200
201 // Add control for number of hops allowed
202 Box box = Box.createHorizontalBox();
203
204 Mnemonic mnHops =
205 new Mnemonic(ResourceStrings.getString("service_options_hops"));
206 JLabel label = new JLabel(mnHops.getString());
207 label.setToolTipText(mnHops.getString());
208 label.setDisplayedMnemonic(mnHops.getMnemonic());
209
210 label.setForeground(Color.black);
211 box.add(label);
212 box.add(Box.createHorizontalStrut(5));
213 relayHops = new IntegerField();
214 label.setLabelFor(relayHops);
215 box.add(relayHops);
216 bag.setConstraints(box, con);
217 optionsPanel.add(box);
218
219 // Add control for verbose logging
220 verboseLogging = new JCheckBox(
221 ResourceStrings.getString("service_options_verbose"), false);
222 verboseLogging.setToolTipText(
223 ResourceStrings.getString("service_options_verbose"));
224 ++con.gridy;
225 bag.setConstraints(verboseLogging, con);
226 optionsPanel.add(verboseLogging);
227
228 // Add control for transaction logging on/off and facility to use
229 box = Box.createHorizontalBox();
230 logTransactions = new JCheckBox(
231 ResourceStrings.getString("service_options_log_transactions"),
232 false);
233 logTransactions.setToolTipText(
234 ResourceStrings.getString("service_options_log_transactions"));
235 logTransactions.setAlignmentY((float)0.5);
236 box.add(logTransactions);
237 box.add(Box.createHorizontalStrut(5));
238 logFacility = new JComboBox(DhcpdOptions.getLoggingFacilities());
239 logFacility.setAlignmentY((float)0.5);
240 box.add(logFacility);
241 ++con.gridy;
242 bag.setConstraints(box, con);
243 optionsPanel.add(box);
244 // Enable logging facility choices only when logging is turned on
245 logTransactions.addActionListener(new ActionListener() {
246 public void actionPerformed(ActionEvent e) {
247 logFacility.setEnabled(logTransactions.isSelected());
248 }
249 });
250
251 /*
252 * The main tab has two different displays depending on whether it's
253 * a relay or a full-fledged server.
254 */
255 if (!DhcpmgrApplet.modeIsRelay) {
256 // Add control for duplicate detection using ICMP
257 detectDuplicates = new JCheckBox(
258 ResourceStrings.getString("service_options_detect_duplicates"),
259 true);
260 detectDuplicates.setToolTipText(
261 ResourceStrings.getString("service_options_detect_duplicates"));
262 ++con.gridy;
263 bag.setConstraints(detectDuplicates, con);
264 optionsPanel.add(detectDuplicates);
265
266 // Add control for automatic reload of dhcptab and period
267 box = Box.createHorizontalBox();
268 reloadEnabled = new JCheckBox(
269 ResourceStrings.getString("service_options_reload_dhcptab"));
270 reloadEnabled.setToolTipText(ResourceStrings.getString(
271 "service_options_reload_dhcptab"));
272 reloadEnabled.setAlignmentY((float)0.5);
273 box.add(reloadEnabled);
274 box.add(Box.createHorizontalStrut(5));
275 reloadInterval = new IntegerField();
276 reloadInterval.setAlignmentY((float)0.5);
277 box.add(reloadInterval);
278 box.add(Box.createHorizontalStrut(5));
279
280 Mnemonic mnMins =
281 new Mnemonic(ResourceStrings.getString(
282 "service_options_reload_minutes"));
283 label = new JLabel(mnMins.getString());
284 label.setLabelFor(reloadInterval);
285 label.setToolTipText(mnMins.getString());
286 label.setDisplayedMnemonic(mnMins.getMnemonic());
287
288 label.setForeground(Color.black);
289 label.setAlignmentY((float)0.5);
290 box.add(label);
291 ++con.gridy;
292 bag.setConstraints(box, con);
293 optionsPanel.add(box);
294
295 // Add control for DNS dynamic update and timeout value
296 box = Box.createHorizontalBox();
297 dnsUpdateEnabled = new JCheckBox(
298 ResourceStrings.getString("service_options_update_dns"));
299 dnsUpdateEnabled.setToolTipText(
300 ResourceStrings.getString("service_options_update_dns"));
301 dnsUpdateEnabled.setAlignmentY((float)0.5);
302 box.add(dnsUpdateEnabled);
303 box.add(Box.createHorizontalStrut(5));
304 ++con.gridy;
305 bag.setConstraints(box, con);
306 optionsPanel.add(box);
307
308 box = Box.createHorizontalBox();
309 dnsTimeout = new IntegerField();
310 dnsTimeout.setAlignmentY((float)0.10);
311 box.add(Box.createHorizontalStrut(25));
312
313 Mnemonic mnDNS =
314 new Mnemonic(ResourceStrings.getString(
315 "service_options_timeout_dns"));
316 label = new JLabel(mnDNS.getString());
317 label.setLabelFor(dnsTimeout);
318 label.setToolTipText(mnDNS.getString());
319 label.setDisplayedMnemonic(mnDNS.getMnemonic());
320
321 label.setForeground(Color.black);
322 label.setAlignmentY((float)0.5);
323 box.add(label);
324 box.add(Box.createHorizontalStrut(5));
325 box.add(dnsTimeout);
326 box.add(Box.createHorizontalStrut(5));
327 label = new JLabel(
328 ResourceStrings.getString("service_options_seconds"));
329 label.setLabelFor(box);
330 label.setToolTipText(ResourceStrings.getString(
331 "service_options_seconds"));
332 label.setForeground(Color.black);
333 label.setAlignmentY((float)0.5);
334 box.add(label);
335 ++con.gridy;
336 bag.setConstraints(box, con);
337 optionsPanel.add(box);
338
339 // Add control for length of time to cache offers
340 box = Box.createHorizontalBox();
341
342 Mnemonic mnCache =
343 new Mnemonic(ResourceStrings.getString(
344 "service_options_cache"));
345 label = new JLabel(mnCache.getString());
346 label.setToolTipText(mnCache.getString());
347 label.setDisplayedMnemonic(mnCache.getMnemonic());
348
349 label.setForeground(Color.black);
350 box.add(label);
351 box.add(Box.createHorizontalStrut(5));
352 cacheTime = new IntegerField();
353 label.setLabelFor(cacheTime);
354 box.add(cacheTime);
355 box.add(Box.createHorizontalStrut(5));
356 label = new JLabel(
357 ResourceStrings.getString("service_options_seconds"));
358 label.setLabelFor(box);
359 label.setToolTipText(ResourceStrings.getString(
360 "service_options_seconds"));
361 label.setForeground(Color.black);
362 box.add(label);
363 ++con.gridy;
364 bag.setConstraints(box, con);
365 optionsPanel.add(box);
366
367 // Add choices for BOOTP compatibility behavior: none, auto, manual
368 JPanel panel = new JPanel();
369 panel.setLayout(new GridLayout(3, 1));
370 Border b = BorderFactory.createTitledBorder(
371 BorderFactory.createLineBorder(Color.black),
372 ResourceStrings.getString("service_options_bootp_compat"));
373 panel.setBorder(BorderFactory.createCompoundBorder(b,
374 BorderFactory.createEmptyBorder(5, 5, 5, 5)));
375
376 ButtonGroup bootpCompat = new ButtonGroup();
377
378 noBootp = new JRadioButton(
379 ResourceStrings.getString("service_options_bootp_none"), true);
380 noBootp.setToolTipText(
381 ResourceStrings.getString("service_options_bootp_none"));
382 bootpCompat.add(noBootp);
383 panel.add(noBootp);
384
385 autoBootp = new JRadioButton(
386 ResourceStrings.getString("service_options_bootp_auto"), false);
387 autoBootp.setToolTipText(
388 ResourceStrings.getString("service_options_bootp_auto"));
389 bootpCompat.add(autoBootp);
390 panel.add(autoBootp);
391
392 manualBootp = new JRadioButton(
393 ResourceStrings.getString("service_options_bootp_manual"),
394 false);
395 manualBootp.setToolTipText(
396 ResourceStrings.getString("service_options_bootp_manual"));
397 bootpCompat.add(manualBootp);
398 panel.add(manualBootp);
399
400 ++con.gridy;
401 con.fill = GridBagConstraints.HORIZONTAL;
402 bag.setConstraints(panel, con);
403 optionsPanel.add(panel);
404
405 // Enable reload interval only when reload option is checked
406 reloadEnabled.addActionListener(new ActionListener() {
407 public void actionPerformed(ActionEvent e) {
408 reloadInterval.setEnabled(reloadEnabled.isSelected());
409 }
410 });
411 // Enable DNS timeout only when DNS update option is checked
412 dnsUpdateEnabled.addActionListener(new ActionListener() {
413 public void actionPerformed(ActionEvent e) {
414 dnsTimeout.setEnabled(dnsUpdateEnabled.isSelected());
415 }
416 });
417 } else {
418 /*
419 * In relay mode the only other thing we can control is list of
420 * servers which we forward requests to.
421 */
422 serverList = new IPAddressList();
423 Border tb = BorderFactory.createTitledBorder(
424 BorderFactory.createLineBorder(Color.black),
425 ResourceStrings.getString("dhcp_servers"));
426 serverList.setBorder(BorderFactory.createCompoundBorder(tb,
427 BorderFactory.createEmptyBorder(5, 5, 5, 5)));
428 ++con.gridy;
429 bag.setConstraints(serverList, con);
430 optionsPanel.add(serverList);
431 }
432
433 tabbedPane.addTab(ResourceStrings.getString("service_options_options"),
434 optionsPanel);
435
436 // Panel for interfaces
437 monitoredTable = new JTable(new InterfaceTableModel());
438 ignoredTable = new JTable(new InterfaceTableModel());
439 monitoredTable.setSelectionMode(
440 ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
441 ignoredTable.setSelectionMode(
442 ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
443
444 Box interfaceBox = Box.createHorizontalBox();
445
446 // The list of interfaces we're monitoring goes on the left
447 JPanel panel = new JPanel(new BorderLayout(5, 5));
448
449 Mnemonic mnMon =
450 new Mnemonic(ResourceStrings.getString(
451 "service_options_monitored"));
452 JLabel servOptsLbl = new JLabel(mnMon.getString());
453 servOptsLbl.setLabelFor(monitoredTable);
454 servOptsLbl.setToolTipText(mnMon.getString());
455 servOptsLbl.setDisplayedMnemonic(mnMon.getMnemonic());
456
457 panel.add(servOptsLbl, BorderLayout.NORTH);
458
459 JScrollPane scrollPane = new JScrollPane(monitoredTable);
460 Dimension d = monitoredTable.getPreferredScrollableViewportSize();
461 d.height = 100;
462 d.width = 210;
463 monitoredTable.setPreferredScrollableViewportSize(d);
464 panel.add(scrollPane, BorderLayout.CENTER);
465 interfaceBox.add(panel);
466 interfaceBox.add(Box.createHorizontalStrut(10));
467
468 // The buttons to move items between the lists go in the middle
469 panel = new JPanel(new VerticalButtonLayout());
470 leftButton = new LeftButton();
471 rightButton = new RightButton();
472 rightButton.setEnabled(false);
473 leftButton.setEnabled(false);
474 panel.add(rightButton);
475 panel.add(leftButton);
476 interfaceBox.add(panel);
477 interfaceBox.add(Box.createHorizontalStrut(10));
478
479 // The list of interfaces to ignore is on the right
480 panel = new JPanel(new BorderLayout(5, 5));
481
482 Mnemonic mnIg =
483 new Mnemonic(ResourceStrings.getString("service_options_ignored"));
484 JLabel optsIgnLbl = new JLabel(mnIg.getString());
485 optsIgnLbl.setLabelFor(ignoredTable);
486 optsIgnLbl.setToolTipText(mnIg.getString());
487 optsIgnLbl.setDisplayedMnemonic(mnIg.getMnemonic());
488
489 panel.add(optsIgnLbl, BorderLayout.NORTH);
490
491 scrollPane = new JScrollPane(ignoredTable);
492 d = ignoredTable.getPreferredScrollableViewportSize();
493 d.height = 100;
494 d.width = 210;
495 ignoredTable.setPreferredScrollableViewportSize(d);
496 panel.add(scrollPane, BorderLayout.CENTER);
497 interfaceBox.add(panel);
498
499 // Now create the tab for the interface manipulation
500 panel = new JPanel(new BorderLayout());
501 panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
502 panel.add(interfaceBox, BorderLayout.CENTER);
503 tabbedPane.addTab(
504 ResourceStrings.getString("service_options_interfaces"), panel);
505
506 // tab for Addresses
507 if (!DhcpmgrApplet.modeIsRelay) {
508 JPanel addrsPanel = new JPanel(new BorderLayout());
509 addrsPanel.setBorder(
510 BorderFactory.createEmptyBorder(10, 10, 10, 10));
511
512 // Add control for DHCP OWNER_IP option and values
513 box = Box.createHorizontalBox();
514 owneripEnabled = new JCheckBox(
515 ResourceStrings.getString("service_options_owner_ip"));
516 owneripEnabled.setToolTipText(
517 ResourceStrings.getString("service_options_owner_ip"));
518 owneripEnabled.setAlignmentY((float)0.5);
519 box.add(owneripEnabled);
520 box.add(Box.createHorizontalStrut(5));
521 addrsPanel.add(box, BorderLayout.NORTH);
522
523 owneripList = new IPAddressList();
524 Border tb = BorderFactory.createTitledBorder(
525 BorderFactory.createLineBorder(Color.black),
526 ResourceStrings.getString(
527 "service_options_owner_ip_addresses"));
528 owneripList.setBorder(BorderFactory.createCompoundBorder(tb,
529 BorderFactory.createEmptyBorder(5, 5, 5, 5)));
530 addrsPanel.add(owneripList, BorderLayout.CENTER);
531 // Enable OWNER_IP Addresses only when owner_ip option is checked
532 owneripEnabled.addActionListener(new ActionListener() {
533 public void actionPerformed(ActionEvent e) {
534 owneripList.setEnabled(owneripEnabled.isSelected());
535 }
536 });
537 // now add the tab for Addresses
538 tabbedPane.addTab(
539 ResourceStrings.getString("service_options_addresses"),
540 addrsPanel);
541 }
542
543 JPanel borderPanel = new JPanel(new BorderLayout());
544 borderPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
545 borderPanel.add(tabbedPane, BorderLayout.CENTER);
546
547 mainPanel.add(borderPanel, BorderLayout.NORTH);
548
549 /*
550 * Allow them to specify server should be restarted when these changes
551 * are applied
552 */
553 restartServer = new JCheckBox(
554 ResourceStrings.getString("service_options_restart"));
555 restartServer.setToolTipText(
556 ResourceStrings.getString("service_options_restart"));
557 panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
558 panel.add(restartServer);
559 mainPanel.add(panel, BorderLayout.CENTER);
560
561 buttonPanel.setOkEnabled(true);
562
563 // Handle enable and disable of buttons based on selection state
564 monitoredTable.getSelectionModel().addListSelectionListener(
565 new ListSelectionListener() {
566 public void valueChanged(ListSelectionEvent e) {
567 if (monitoredTable.getSelectedRowCount() != 0 &&
568 monitoredTable.getRowCount() > 0) {
569 rightButton.setEnabled(true);
570 ignoredTable.getSelectionModel().clearSelection();
571 } else {
572 rightButton.setEnabled(false);
573 }
574 }
575 });
576
577 ignoredTable.getSelectionModel().addListSelectionListener(
578 new ListSelectionListener() {
579 public void valueChanged(ListSelectionEvent e) {
580 if (ignoredTable.getSelectedRowCount() != 0 &&
581 ignoredTable.getRowCount() > 0) {
582 leftButton.setEnabled(true);
583 monitoredTable.getSelectionModel().clearSelection();
584 } else {
585 leftButton.setEnabled(false);
586 }
587 }
588 });
589
590 // Handle button presses
591 rightButton.addActionListener(new ActionListener() {
592 public void actionPerformed(ActionEvent e) {
593 int [] rows = monitoredTable.getSelectedRows();
594 if (rows == null) {
595 return;
596 }
597 InterfaceTableModel monitoredModel =
598 (InterfaceTableModel)monitoredTable.getModel();
599 InterfaceTableModel ignoredModel =
600 (InterfaceTableModel)ignoredTable.getModel();
601 /*
602 * Now do the adds, then the removes; otherwise the row numbers
603 * we just got might be wrong
604 */
605 Vector removals = new Vector();
606 for (int i = 0; i < rows.length; ++i) {
607 IPInterface ipif = monitoredModel.getInterfaceAt(rows[i]);
608 ignoredModel.addInterface(ipif);
609 removals.addElement(ipif);
610 }
611 Enumeration en = removals.elements();
612 while (en.hasMoreElements()) {
613 monitoredModel.deleteInterface(
614 (IPInterface)en.nextElement());
615 }
616 /*
617 * Clear the selection; this prevents exceptions from selection
618 * pointing at rows that are gone
619 */
620 monitoredTable.getSelectionModel().clearSelection();
621 }
622 });
623
624 leftButton.addActionListener(new ActionListener() {
625 public void actionPerformed(ActionEvent e) {
626 int [] rows = ignoredTable.getSelectedRows();
627 if (rows == null) {
628 return;
629 }
630 InterfaceTableModel monitoredModel =
631 (InterfaceTableModel)monitoredTable.getModel();
632 InterfaceTableModel ignoredModel =
633 (InterfaceTableModel)ignoredTable.getModel();
634 /*
635 * Now do the adds, then the removes; otherwise the row numbers
636 * we just got might be wrong
637 */
638 Vector removals = new Vector();
639 for (int i = 0; i < rows.length; ++i) {
640 IPInterface ipif = ignoredModel.getInterfaceAt(rows[i]);
641 monitoredModel.addInterface(ipif);
642 removals.addElement(ipif);
643 }
644 Enumeration en = removals.elements();
645 while (en.hasMoreElements()) {
646 ignoredModel.deleteInterface((IPInterface)en.nextElement());
647 }
648 /*
649 * Clear the selection; this prevents exceptions from selection
650 * pointing at rows that are gone
651 */
652 ignoredTable.getSelectionModel().clearSelection();
653 }
654 });
655
656
657 return mainPanel;
658 }
659
660 // Save a copy of the option settings so reset can work
661 private void setOptions(DhcpdOptions o) {
662 originalOptions = (DhcpdOptions)o.clone();
663 options = o;
664 }
665
666 // Reset all controls to initial values
667 private void resetValues() {
668 // Main tab parameters; first verbose logging
669 verboseLogging.setSelected(options.isVerbose());
670 // Relay hops
671 if (options.isRelayHops()) {
672 relayHops.setValue(options.getRelayHops());
673 } else {
674 relayHops.setValue(DhcpdOptions.DSVC_CV_HOPS);
675 }
676 // Set logging controls
677 logTransactions.setSelected(options.isLogging());
678 logFacility.setEnabled(options.isLogging());
679 if (options.isLogging()) {
680 logFacility.setSelectedItem(options.getLogging());
681 } else {
682 logFacility.setSelectedIndex(0);
683 }
684
685 if (!DhcpmgrApplet.modeIsRelay) {
686 // Set bootp compat. controls
687 noBootp.setSelected(!options.isBootpCompatible());
688 if (options.isBootpCompatible()) {
689 autoBootp.setSelected(options.isBootpAutomatic());
690 manualBootp.setSelected(!options.isBootpAutomatic());
691 }
692 detectDuplicates.setSelected(options.isICMPVerify());
693 reloadEnabled.setSelected(options.isRescan());
694 reloadInterval.setEnabled(options.isRescan());
695 owneripEnabled.setSelected(options.isOwnerip());
696 owneripList.setEnabled(options.isOwnerip());
697 dnsUpdateEnabled.setSelected(options.isDnsUpdated());
698 dnsTimeout.setEnabled(options.isDnsUpdated());
699
700 // Set rescan interval to default if it's not specified
701 if (options.isRescan()) {
702 reloadInterval.setValue(options.getRescan());
703 } else {
704 reloadInterval.setValue(DEFAULT_RESCAN_INTERVAL);
705 }
706
707 // Set owner_ip to default if it's not specified
708 if (options.isOwnerip()) {
709 owneripList.setAddressList(options.getOwnerip());
710 }
711 // Set DNS timeout to default if it's not specified
712 if (options.isDnsUpdated()) {
713 dnsTimeout.setValue(options.getDnsTimeout());
714 } else {
715 dnsTimeout.setValue(DhcpdOptions.DSVC_CV_NSU_TO);
716 }
717 if (options.isOfferTtl()) {
718 cacheTime.setValue(options.getOfferTtl());
719 } else {
720 cacheTime.setValue(DhcpdOptions.DSVC_CV_OFFER_TTL);
721 }
722 } else {
723 // In relay case only the server list is available
724 serverList.setAddressList(options.getRelay());
725 }
726
727 // Interfaces tab
728 try {
729 IPInterface[] interfaces = new IPInterface[0];
730 try {
731 interfaces =
732 DataManager.get().getDhcpServiceMgr().getInterfaces();
733 } catch (BridgeException e) {
734 // we're not configured yet, apparently
735 interfaces = null;
736 }
737 InterfaceTableModel monitoredModel =
738 (InterfaceTableModel)monitoredTable.getModel();
739 InterfaceTableModel ignoredModel =
740 (InterfaceTableModel)ignoredTable.getModel();
741 if (options.isInterfaces()) {
742 ignoredModel.setInterfaceList(interfaces);
743 monitoredModel.setInterfaceList(null);
744 StringTokenizer st =
745 new StringTokenizer(options.getInterfaces(), ",");
746 while (st.hasMoreTokens()) {
747 IPInterface ipif =
748 ignoredModel.getInterface(st.nextToken());
749 if (ipif != null) {
750 monitoredModel.addInterface(ipif);
751 ignoredModel.deleteInterface(ipif);
752 }
753 }
754 } else {
755 monitoredModel.setInterfaceList(interfaces);
756 ignoredModel.setInterfaceList(null);
757 }
758 } catch (Throwable e) {
759 e.printStackTrace();
760 }
761
762 // Default to restarting server
763 restartServer.setSelected(true);
764 }
765
766 /**
767 * User pressed OK, do what we think is necessary
768 */
769 protected void doOk() {
770 try {
771 options.setVerbose(verboseLogging.isSelected());
772 if (relayHops.getValue() != DhcpdOptions.DSVC_CV_HOPS) {
773 options.setRelayHops(true, new Integer(relayHops.getValue()));
774 } else {
775 options.setRelayHops(false, null);
776 }
777 options.setLogging(logTransactions.isSelected(),
778 (Integer)logFacility.getSelectedItem());
779
780 if (!DhcpmgrApplet.modeIsRelay) {
781 options.setBootpCompatible(!noBootp.isSelected(),
782 autoBootp.isSelected());
783 options.setICMPVerify(detectDuplicates.isSelected());
784 if (reloadEnabled.isSelected() &&
785 reloadInterval.getValue() != 0) {
786 options.setRescan(true,
787 new Integer(reloadInterval.getValue()));
788 } else {
789 options.setRescan(false, null);
790 }
791
792 if (owneripEnabled.isSelected()) {
793 options.setOwnerip(true,
794 owneripList.getAddressListString());
795 } else {
796 options.setOwnerip(false, null);
797 }
798
799 if (dnsUpdateEnabled.isSelected()) {
800 options.setDnsTimeout(true,
801 new Integer(dnsTimeout.getValue()));
802 } else {
803 options.setDnsTimeout(false, null);
804 }
805 if (cacheTime.getValue() != DhcpdOptions.DSVC_CV_OFFER_TTL) {
806 options.setOfferTtl(true,
807 new Integer(cacheTime.getValue()));
808 } else {
809 options.setOfferTtl(false, null);
810 }
811 } else {
812 options.setRelay(true, serverList.getAddressListString());
813 }
814 if (monitoredTable.getRowCount() == 0) {
815 // XXX Need to disable OK when this is the case
816 return;
817 }
818 if (ignoredTable.getRowCount() != 0) {
819 /*
820 * If nothing is ignored then let server default to all
821 * interfaces
822 */
823 options.setInterfaces(true, ((InterfaceTableModel)
824 monitoredTable.getModel()).getInterfaceList());
825 } else {
826 options.setInterfaces(false, null);
827 }
828 DataManager.get().getDhcpServiceMgr().writeDefaults(options);
829 if (restartServer.isSelected()) {
830 DataManager.get().getDhcpServiceMgr().shutdown();
831 // Wait 5 secs for server to try to shutdown
832 Thread.sleep(5000);
833 DataManager.get().getDhcpServiceMgr().startup();
834 }
835 fireActionPerformed();
836 setVisible(false);
837 dispose();
838 } catch (Exception e) {
839 MessageFormat form = null;
840 Object [] args = new Object[2];
841 form = new MessageFormat(
842 ResourceStrings.getString("service_options_error"));
843 args[0] = e.getMessage();
844 JOptionPane.showMessageDialog(this, form.format(args),
845 ResourceStrings.getString("server_error_title"),
846 JOptionPane.ERROR_MESSAGE);
847 }
848 }
849
850 /**
851 * Return help system lookup key
852 */
853 protected String getHelpKey() {
854 if (DhcpmgrApplet.modeIsRelay) {
855 return "modify_relay";
856 } else {
857 return "modify_server";
858 }
859 }
860
861 /**
862 * User pressed reset; go back to starting value
863 */
864 protected void doReset() {
865 setOptions(originalOptions);
866 resetValues();
867 }
868
869 /**
870 * Notify our invoker that we're done
871 */
872 protected void fireActionPerformed() {
873 fireActionPerformed(this, DialogActions.OK);
874 }
875 }