1
/** BEGIN COPYRIGHT BLOCK
2
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
3
* Copyright (C) 2005 Red Hat, Inc.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; version 2
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
* END COPYRIGHT BLOCK **/
21
package com.netscape.management.admserv;
25
import java.awt.event.*;
29
import com.netscape.management.client.*;
30
import com.netscape.management.client.console.*;
31
import com.netscape.management.admserv.panel.IRestartControl;
32
import com.netscape.management.admserv.config.BaseConfigPanel;
33
import com.netscape.management.client.topology.*;
34
import com.netscape.management.client.util.*;
35
import com.netscape.management.nmclf.*;
36
import com.netscape.management.admserv.panel.*;
37
import netscape.ldap.*;
40
* Netscape admin server configuration entry point. The directory
41
* server needs to contain the name of this class in order for the topology
42
* view to load this class.
44
public class AdminServer extends AbstractServerObject implements SuiConstants {
45
public static ResourceSet _resource = new ResourceSet("com.netscape.management.admserv.admserv");
47
ConsoleInfo _consoleInfo;
49
private int adminUrlNodeDataIndex = -1;
52
* Implements the IServerObject interface. Initializes the page with
53
* the global information.
55
* @param info - global information.
57
public void initialize(ConsoleInfo info) {
58
super.initialize(info);
60
setIcon(new RemoteImage(_resource.getString("admin", "smallIcon")));
61
_canRestartFromConsole = !info.getAdminURL().startsWith("https");
65
* Restart activator is used as a repository for various restart control parameters.
66
* The reference to the activator is stored in the ConsoleInfo. panel/RestartOperation.java
67
* is reading the restart parameters which are set by config panels and operations.
69
protected boolean _needsAutoRestart = false;
70
protected boolean _canRestartFromConsole; // set in initialize()
71
protected String _postRestartURL = null;
72
protected boolean _isShutdown = false;
74
private IRestartControl _restartControl = new IRestartControl() {
75
public void setNeedsAutoRestart(boolean flag) {
76
_needsAutoRestart = flag;
78
public boolean needsAutoRestart() {
79
return _needsAutoRestart;
82
public void setCanRestartFromConsole(boolean flag) {
83
_canRestartFromConsole = flag;
85
public boolean canRestartFromConsole() {
86
return _canRestartFromConsole;
89
public void setPostRestartURL(String url) {
90
_postRestartURL = url;
93
public String getPostRestartURL() {
94
return _postRestartURL;
97
public void setServerShutdown(boolean flag) {
100
public boolean isServerShutdown() {
107
/* TODO move to AdminTaskPage/ResourcePage/FrameworkInitializer
108
IFrameworkListener _closeListener = new IFrameworkListener() {
109
public void pageSelectionChanged(FrameworkEvent e) {}
111
public void actionViewClosing(FrameworkEvent e) throws CloseVetoException {
112
Debug.println("window closing, needs restart =" + _needsAutoRestart);
113
if (_restartControl.needsAutoRestart()) {
114
SuiOptionPane.showMessageDialog(_frame,
115
_resource.getString("restart","mustRestart"),
116
_resource.getString("restart","title"),
117
SuiOptionPane.INFORMATION_MESSAGE);
119
AdminOperation operation = new RestartOperation(_consoleInfo);
120
operation.monitorOperation("");
121
String title = _resource.getString("taskName","restart");
122
DialogFrame dialog = new DialogFrame(_frame, title, operation.getPanel());
123
dialog.setVisible(true);
130
private boolean run(IPage viewInstance) {
131
// do not run if the server is down
132
if (getServerStatus() == IServerObject.STATUS_STOPPED) {
133
Frame frame = viewInstance.getFramework().getJFrame();
134
String title = _resource.getString("error","OpenServerTitle");
135
String msg = java.text.MessageFormat.format(
136
_resource.getString("error","CanNotOpenServer"),
137
new Object[]{ getName()});
138
BaseConfigPanel.clearProgressIndicator(
139
(Component) viewInstance);
140
SuiOptionPane.showMessageDialog(frame, msg, title,
141
SuiOptionPane.ERROR_MESSAGE);
145
// Augment the console info with the server name
146
_consoleInfo.put("SIE", getSIE());
147
_consoleInfo.put("SIE_VERSION", getProductVersion());
148
_consoleInfo.put("SERVER_NAME", getName());
149
_consoleInfo.put("HOST_NAME", getHostName());
150
_consoleInfo.put(IRestartControl.ID, _restartControl);
158
* This function is called when the admin server is double clicked on the topology view.
160
public boolean run(IPage viewInstance,
161
IResourceObject selectionList[]) {
163
if (selectionList.length == 1) {
164
return run(viewInstance);
167
// Do not run if the server is down
168
if (getServerStatus() == IServerObject.STATUS_STOPPED) {
169
Frame frame = viewInstance.getFramework().getJFrame();
170
String title = _resource.getString("error","OpenServerTitle");
171
String msg = java.text.MessageFormat.format(
172
_resource.getString("error","CanNotOpenServer"),
173
new Object[]{ getName()});
174
BaseConfigPanel.clearProgressIndicator(
175
(Component) viewInstance);
176
SuiOptionPane.showMessageDialog(frame, msg, title,
177
SuiOptionPane.ERROR_MESSAGE);
181
for (int i = 0; i < selectionList.length; i++) {
182
if (!(selectionList[i] instanceof ServerNode)) {
183
Debug.println("can't run, selection is " +
184
selectionList[i].getClass().getName());
187
ServerNode node = (ServerNode) selectionList[i];
188
if (!(node.getServerObject() instanceof AdminServer)) {
189
Debug.println("can't run, server is " +
190
node.getServerObject().getClass().getName());
202
protected void createFramework() {
203
Framework frame = new Framework(
204
new AdminFrameworkInitializer(_consoleInfo));
205
StatusItemSecureMode _statusSecureMode =
206
new StatusItemSecureMode(Framework.STATUS_SECURE_MODE);
207
_statusSecureMode.setSecureMode(
208
_consoleInfo.getAdminURL().startsWith("https"));
209
frame.addStatusItem(_statusSecureMode, IStatusItem.LEFTFIRST);
210
_statusSecureMode.setToolTipText(_consoleInfo.getAdminURL());
214
// return the host in which this server is installed
215
protected String getHostName() {
216
return (String)_nodeDataTable.get("serverHostName");
219
// return SIE name "admin-serv-<host>"
220
protected String getSIE() {
221
return (String)_nodeDataTable.get("cn");
224
// return the Server version number e.g. "4.1"
225
protected String getProductVersion() {
226
return (String)_nodeDataTable.get("nsProductVersion");
229
public ConsoleInfo getConsoleInfo() {
234
private URL _serverURL = null;
235
private URLConnection _serverConnection = null;
238
* Implements the IServerObject interface.
240
public synchronized int getServerStatus() {
241
// for admin server, just check whether connections are accepted on the URL;
242
// if the URL does not respond, then it is down. Otherwise it is up.
244
// In case the method is called before AdminServer in initialized
245
if (_consoleInfo == null) {
246
return STATUS_UNKNOWN;
251
String adminURL = _consoleInfo.getAdminURL() + "admin-serv/tasks/operation/StatusPing";
252
AdmTask task = new AdmTask(new URL(adminURL),
253
_consoleInfo.getAuthenticationDN(),
254
_consoleInfo.getAuthenticationPassword());
256
int status = task.getStatus();
258
_serverStatus = STATUS_STARTED;
259
} else if (task.getException() != null && task.getException()
260
instanceof java.net.SocketException) {
261
_serverStatus = STATUS_STOPPED;
263
_serverStatus = STATUS_UNKNOWN;
265
return _serverStatus;
266
} catch (MalformedURLException ex) {
267
Debug.println("ERROR AdminConfigData.isRunning: bad URL " +
268
_consoleInfo.getAdminURL());
269
return _serverStatus = STATUS_UNKNOWN;
276
* Implements the IServerObject interface. This will launch the
277
* necessary CGI to clone the configuration of the reference server
278
* to this server. Only the following attributes are cloned:
280
* <li>nsadminaccessaddresses
281
* <li>nsadminaccesshosts
282
* <li>nsadmincachelifetime
283
* <li>nsadminenabledsgw
284
* <li>nsadminenableenduser
285
* <li>nsadminoneacldir
286
* <li>nsdefaultacceptlanguage
289
* @param referenceDN - DN of server to clone from.
291
public void cloneFrom(String referenceDN) {
292
String configDN = "cn=configuration," + referenceDN;
293
String configURL = null;
295
// First, get the configuration information to clone using the referenceDN.
296
LDAPConnection ldc = _consoleInfo.getLDAPConnection();
298
ldc = new LDAPConnection();
300
if (ldc.isConnected() == false) {
301
ldc.connect(_consoleInfo.getHost(), _consoleInfo.getPort(),
302
_consoleInfo.getAuthenticationDN(),
303
_consoleInfo.getAuthenticationPassword());
305
LDAPEntry entry = ldc.read(configDN);
306
String addresses = LDAPUtil.flatting(
307
entry.getAttribute("nsadminaccessaddresses",
308
LDAPUtil.getLDAPAttributeLocale()));
309
String hosts = LDAPUtil.flatting(
310
entry.getAttribute("nsadminaccesshosts",
311
LDAPUtil.getLDAPAttributeLocale()));
312
String cache = LDAPUtil.flatting(
313
entry.getAttribute("nsadmincachelifetime",
314
LDAPUtil.getLDAPAttributeLocale()));
315
String dsgw = LDAPUtil.flatting(
316
entry.getAttribute("nsadminenabledsgw",
317
LDAPUtil.getLDAPAttributeLocale()));
318
String endUser = LDAPUtil.flatting(
319
entry.getAttribute("nsadminenableenduser",
320
LDAPUtil.getLDAPAttributeLocale()));
321
String oneAclDir = LDAPUtil.flatting(
322
entry.getAttribute("nsadminoneacldir",
323
LDAPUtil.getLDAPAttributeLocale()));
324
String defaultAccLang = LDAPUtil.flatting(
325
entry.getAttribute("nsdefaultacceptlanguage",
326
LDAPUtil.getLDAPAttributeLocale()));
328
boolean enableEndUser;
329
if (dsgw != null && dsgw.equalsIgnoreCase("off")) {
334
if (endUser != null && endUser.equalsIgnoreCase("off")) {
335
enableEndUser = false;
337
enableEndUser = true;
340
// Invoke CGI to configure the server with the cloned configuration information.
341
// Some attributes, such as nsadminenableenduser, must be forced set.
343
new String(_consoleInfo.getAdminURL() + "admin-serv/tasks/Configuration/ServerSetup?op=force_set" +
344
"&configuration.nsadminaccessaddresses=" +
345
addresses + "&configuration.nsadminaccesshosts=" +
346
hosts + "&configuration.nsadmincachelifetime=" +
347
cache + "&configuration.nsadminoneacldir=" + oneAclDir +
348
"&configuration.nsdefaultacceptlanguage=" +
350
if (enableDSGW == true) {
351
configURL = configURL + "&configuration.nsadminenabledsgw=";
353
configURL = configURL + "&configuration.nsadminenabledsgw=off";
355
if (enableEndUser == true) {
356
configURL = configURL + "&configuration.nsadminenableenduser=";
358
configURL = configURL + "&configuration.nsadminenableenduser=off";
360
Debug.println("TRACE AdminServer.cloneFrom: configURL = " +
363
// Need to make this another thread. Display a dialog to show progress!
364
URL configAdminURL = new URL(configURL);
365
// Is authenticating with the ConsoleInfo correct???
366
AdmTask task = new AdmTask(configAdminURL,
367
_consoleInfo.getAuthenticationDN(),
368
_consoleInfo.getAuthenticationPassword());
369
int execStatus = task.exec();
370
int taskStatus = task.getStatus();
371
String title = _resource.getString("status","cloneTitle");
372
if (execStatus == 0 && taskStatus == 0) {
373
Debug.println("TRACE AdminServer.cloneFrom: config CGI succeeded!");
374
String msg = java.text.MessageFormat.format(
375
_resource.getString("status",
376
"cloneSucceeded"), new Object[]{ getName()});
377
SuiOptionPane.showMessageDialog(null, msg, title,
378
SuiOptionPane.INFORMATION_MESSAGE);
380
// Either the exec or the task failed.
382
"ERROR AdminServer.cloneFrom: config CGI status = " +
383
(execStatus == 0 ? taskStatus : execStatus));
384
String msg = java.text.MessageFormat.format(
385
_resource.getString("status", "cloneFailed"),
386
new Object[]{ getName()});
387
SuiOptionPane.showMessageDialog(null, msg, title,
388
SuiOptionPane.ERROR_MESSAGE);
391
catch (LDAPException e) {
392
// TODO: Use SuiOptionPane error message
394
"ERROR AdminServer.cloneFrom: LDAP read failed: " +
397
catch (MalformedURLException e) {
398
// TODO: Use SuiOptionPane error message
399
Debug.println("ERROR AdminServer.cloneFrom: Bad URL: " +
405
* Number of entries for this node.
406
* Implements INodeInfo
408
* @return number of entries
410
public int getNodeDataCount()
412
adminUrlNodeDataIndex = super.getNodeDataCount();
413
return adminUrlNodeDataIndex + 1;
416
public boolean isCloningEnabled()
422
* Return node entry at specified index.
423
* Implements INodeInfo
425
* @return the specified node data
427
public NodeData getNodeData(int index) {
428
if(index == adminUrlNodeDataIndex)
430
String port = null; // legal value, if null, this NodeData will not appear in panel
431
String url = _consoleInfo.getAdminURL();
432
int portIndex = url.lastIndexOf(':');
434
port = url.substring(portIndex+1).replace('/', ' ').trim();
435
return new NodeData("", _resource.getString("infopanel", "Port"), port, false);
439
return super.getNodeData(index);