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 modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
* END COPYRIGHT BLOCK **/
20
package com.netscape.admin.dirserv.cmdln;
22
import javax.swing.UIManager;
23
import javax.swing.JFrame;
24
import com.netscape.management.client.console.ConsoleInfo;
25
import com.netscape.management.client.IPage;
26
import com.netscape.management.client.util.ResourceSet;
27
import com.netscape.management.client.util.Debug;
28
import com.netscape.management.client.comm.CommRecord;
29
import netscape.ldap.util.GetOpt;
30
import com.netscape.admin.dirserv.task.CGITask;
31
import com.netscape.admin.dirserv.DSUtil;
34
* Netscape Admin Server 4.0 class for dealing with Directory Server
40
* @see com.netscape.admin.dirserv.DSAdmin
41
* @see com.netscape.admin.dirserv.CGITask
43
public class DSCommandLine extends CGITask {
45
* Constructor for the commandline utility
47
public DSCommandLine() {
50
/* Set look and feel */
53
UIManager.setLookAndFeel( "com.netscape.management.nmclf.SuiLookAndFeel" );
54
} catch (Exception e) {
55
System.err.println("Cannot load nmc look and feel.");
61
public boolean run (String operation) {
62
/*_sCmd = "bin/shutdown?admin"*/
63
_sCmd = "Tasks/Operation/" + operation;
65
_consoleInfo = new ConsoleInfo();
66
_consoleInfo.setAdminURL( "http://" + m_host + ":" + m_port + "/" );
67
if (operation.equals("Start?InstanceName=slapd-" + m_instance)) {
68
_consoleInfo.put( "ServerInstance", "slapd" ) ;
70
_consoleInfo.put( "ServerInstance", "slapd-" + m_instance ) ;
73
return(super.run( (IPage)null ));
78
protected void showDialog( JFrame frame, String msg, String item,
80
System.err.println( msg );
84
* pass the username to the admin server
86
public String username(Object authObject, CommRecord cr) {
91
* pass the user password to the admin server
93
public String password(Object authObject, CommRecord cr) {
98
* This function is to extract specified parameters from the
99
* arguments list. Returns true if the user entered everything
100
* correctly, false otherwise
101
* @param args list of args
103
protected static GetOpt extractParameters(String privateOpts, String args[]) {
105
GetOpt options = new GetOpt("Hh:p:u:w:i:v" + privateOpts, args);
108
if (options.hasOption('H')) {
112
if (options.hasOption('v')) {
114
Debug.setTrace( true );
118
if (options.hasOption('h'))
119
m_host = options.getOptionParam('h');
122
if (options.hasOption('p')) { /* if the option is -p */
124
m_port = Integer.parseInt(options.getOptionParam('p'));
125
} catch (NumberFormatException e) {
126
System.err.println("Invalid Port");
129
} /* if the option is -p */
132
if (options.hasOption('u'))
133
m_username = options.getOptionParam('u');
136
if (options.hasOption('w'))
137
m_password = options.getOptionParam('w');
140
if (options.hasOption('i'))
141
m_instance = options.getOptionParam('i');
144
if (m_host == null || m_port == 0 ||
145
m_username == null || m_password == null ||
146
m_instance == null) {
157
protected static void doUsage(String appname) {
158
String msg = _resource.getString( "cmdln",
161
System.out.println( msg );
165
* Print error message, using key from derived class
167
protected void printError( String arg ) {
168
if ( _errorCode != 0 ) {
169
String msg = _resource.getString( "dirtask",
170
"error-" + _errorCode + "-msg",
172
System.err.println( msg );
176
protected void printError() {
183
private static String m_host = null;
184
private static int m_port = 0;
185
private static String m_username = null;
186
private static String m_password = null;
187
protected static String m_instance = null;
188
protected static boolean _fTrace = false;
189
protected static ResourceSet _resource = DSUtil._resource;