diff options
author | Endi Sukma Dewata <edewata@redhat.com> | 2012-03-24 02:27:47 -0500 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2012-03-26 11:43:54 -0500 |
commit | 621d9e5c413e561293d7484b93882d985b3fe15f (patch) | |
tree | 638f3d75761c121d9a8fb50b52a12a6686c5ac5c /pki/base/console/src/com/netscape/admin/certsrv/task | |
parent | 40d3643b8d91886bf210aa27f711731c81a11e49 (diff) | |
download | pki-621d9e5c413e561293d7484b93882d985b3fe15f.tar.gz pki-621d9e5c413e561293d7484b93882d985b3fe15f.tar.xz pki-621d9e5c413e561293d7484b93882d985b3fe15f.zip |
Removed unnecessary pki folder.
Previously the source code was located inside a pki folder.
This folder was created during svn migration and is no longer
needed. This folder has now been removed and the contents have
been moved up one level.
Ticket #131
Diffstat (limited to 'pki/base/console/src/com/netscape/admin/certsrv/task')
16 files changed, 0 insertions, 4136 deletions
diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/AuthDialog.java b/pki/base/console/src/com/netscape/admin/certsrv/task/AuthDialog.java deleted file mode 100644 index f4d305096..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/AuthDialog.java +++ /dev/null @@ -1,244 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.awt.*; -import java.util.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import javax.swing.border.*; -import com.netscape.admin.certsrv.*; -import com.netscape.management.client.util.*; -import com.netscape.certsrv.common.*; - -/** - * Display this dialog to get the instance name and password. - * - * @author Christine Ho - * @version $Revision$, $Date$ - */ -public class AuthDialog extends JDialog - implements ActionListener, DocumentListener, MouseListener -{ - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "AUTHDIALOG"; - - private static final int WIDTH = 300; - private static final int HEIGHT = 150; - private JPasswordField mPasswordField; - private boolean mCanceled = true; // exit state of the dialog - private String mPassword; - private JFrame mParentFrame; - private ResourceBundle mResource; - private JButton mOK, mCancel; - private KeyListener mTextFieldKeyListener; - - /*========================================================== - * constructors - *==========================================================*/ - - /** - * @param parent parent frame - */ - public AuthDialog(JFrame parent) { - super(parent, true); - mParentFrame = parent; - mResource = - ResourceBundle.getBundle(CMSAdminResources.class.getName()); - mTextFieldKeyListener = new TextFieldKeyListener(); - setTitle(mResource.getString(PREFIX+"_TITLE")); - setLocationRelativeTo(parent); - - JPanel center = new JPanel(); - getContentPane().setLayout(new BorderLayout()); - GridBagLayout gb = new GridBagLayout(); - GridBagConstraints gbc = new GridBagConstraints(); - center.setLayout(gb); - - JPanel contentPanel = new JPanel(); - GridBagLayout gb1 = new GridBagLayout(); - contentPanel.setLayout(gb1); - - CMSAdminUtil.resetGBC(gbc); - gbc.anchor = gbc.NORTH; - gbc.gridwidth = gbc.REMAINDER; - gbc.weightx = 1.0; - gbc.weighty = 1.0; - gb.setConstraints(contentPanel, gbc); - center.add(contentPanel); - - CMSAdminUtil.resetGBC(gbc); - JLabel lPassword = - new JLabel(mResource.getString(PREFIX+"_LABEL_PASSWORD_LABEL")); - mPasswordField = new JPasswordField(); - mPasswordField.addKeyListener(mTextFieldKeyListener); - mPasswordField.getDocument().addDocumentListener(this); - mPasswordField.addMouseListener(this); - - CMSAdminUtil.addEntryField(contentPanel, lPassword, mPasswordField, - gbc); - - JPanel actionPanel = makeActionPane(); - - CMSAdminUtil.resetGBC(gbc); - gbc.anchor = gbc.NORTH; - gbc.gridwidth = gbc.REMAINDER; - gbc.gridheight = gbc.REMAINDER; - gbc.weightx = 1.0; - gb.setConstraints(actionPanel, gbc); - center.add(actionPanel); - - getContentPane().add("Center",center); - - mCanceled=false; - mPassword = ""; - - setSize( WIDTH, HEIGHT ); - - addWindowListener( - new WindowAdapter() { - public void windowOpened(WindowEvent e) { - mPasswordField.requestFocus(); - } - } - ); - - addWindowListener( - new WindowAdapter() { - public void windowClosing(WindowEvent e) { - //setVisible(false); - dispose(); - mCanceled = true; - } - } - ); - - } - - /*========================================================== - * public methods - *==========================================================*/ - - /** - * return the exit status of the dialog - * - * @return true if the user hits the cancel button. - */ - public boolean isCancel() { - return mCanceled; - } - - public String getPassword() { - return mPassword; - } - - /*========================================================== - * EVNET HANDLER METHODS - *==========================================================*/ - public void actionPerformed(ActionEvent evt) { - if (evt.getSource().equals(mOK)) { - mPassword = mPasswordField.getText().trim(); - mCanceled = false; - //setVisible(false); - this.dispose(); - return; - - } - if (evt.getSource().equals(mCancel)) { - //setVisible(false); - mCanceled = true; - this.dispose(); - return; - } - } - - //== DocumentListener == - public void insertUpdate(DocumentEvent e) { - setButtons(); - } - - public void removeUpdate(DocumentEvent e){ - setButtons(); - } - - public void changedUpdate(DocumentEvent e){ - setButtons(); - } - - //==== MOUSELISTENER ====================== - public void mouseClicked(MouseEvent e) { - setButtons(); - } - - public void mousePressed(MouseEvent e) {} - public void mouseReleased(MouseEvent e) {} - public void mouseEntered(MouseEvent e) {} - public void mouseExited(MouseEvent e) { - setButtons(); - } - - /*========================================================== - * private methods - *==========================================================*/ - - private JPanel makeActionPane() { - mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, - this); - mOK.setEnabled(false); - mCancel = CMSAdminUtil.makeJButton(mResource, PREFIX, "CANCEL", - null, this); - - JButton[] buttons = { mOK, mCancel}; - JButtonFactory.resize( buttons ); - return CMSAdminUtil.makeJButtonPanel(buttons, false); - } - - //set buttons - private void setButtons() { - if (mPasswordField.getText().trim().equals("")){ - mOK.setEnabled(false); - } else { - mOK.setEnabled(true); - getRootPane().setDefaultButton(mOK); - } - } - - /** - * Inner class which handles key events for JTextField components. - */ - class TextFieldKeyListener implements KeyListener - { - public void keyTyped(KeyEvent e) { - } - - public void keyPressed(KeyEvent e) { - } - - public void keyReleased(KeyEvent e) { - if(e.getKeyCode() == KeyEvent.VK_ENTER) { - if (!mPasswordField.getText().trim().equals("")) { - mOK.doClick(); - } - } - } - } - -} diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CGITask.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CGITask.java deleted file mode 100644 index 8406e1005..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CGITask.java +++ /dev/null @@ -1,400 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import com.netscape.admin.certsrv.*; -import java.util.*; -import java.io.*; -import java.net.URL; -import javax.swing.JFrame; -import com.netscape.management.client.TaskObject; -import com.netscape.management.client.IPage; -import com.netscape.management.client.console.ConsoleInfo; -import com.netscape.management.client.comm.*; -import com.netscape.management.client.util.*; - -/** - * Netscape Certificate Server 4.0 CGI base task - * - * @author Jack Pan-Chen - * @version $Revision$, $Date$ - */ -public class CGITask extends CMSTaskObject - implements CommClient -{ - - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "CGITASK"; - - protected boolean mFinished = false; - protected String mCmd = null; - protected String mAdminURL = null; - protected boolean mSuccess = false; - private String mReply = null; - protected String mSection = ""; - protected String mErrorMsg = ""; - protected String mWarnMsg = ""; - - private boolean mForceBasicAuth = false; - - /*========================================================== - * constructors - *==========================================================*/ - public CGITask() { - super(); - } - - /*========================================================== - * public methods - *==========================================================*/ - - /** - * Force the operation to complete with basic auth, instead - * of the default option, which is to first try a non - * authenticated request, then an authenticated one. - */ - - public void setForceBasicAuth(boolean value) { - mForceBasicAuth = value; - } - - /** - * Send an http request to the server and then popup a dialog if the - * operation is successful. - * - * @param viewInstance The calling page - */ - public boolean run(IPage viewInstance) { - if ( mCmd == null ) { - Debug.println( "Could not get execref for " + getDN() ); - return false; - } - - return run( viewInstance, mCmd ); - } - - /** - * Send an http request to the server. Return true if we're sure it - * succeeded, otherwise false. - * - * @param viewInstance The calling page - * @param cmd Command to execute - */ - boolean run(IPage viewInstance, String cmd) { - - // get the admin URL location first - mAdminURL = _consoleInfo.getAdminURL(); - if ( mAdminURL == null ) { - Debug.println( "Could not get adminURL for " + getDN() ); - return false; - } - - // Allow specifying e.g. "slapd-install" for instance - String instance = (String)_consoleInfo.get( cmd ); - - if ( instance == null ) - instance = (String)_consoleInfo.get( "ServerInstance" ); - String fullCmd = mAdminURL + instance + "/" + cmd; - - HttpManager h = new HttpManager(); - // tell the http manager to use UTF8 encoding - h.setResponseTimeout(60000); - h.setSendUTF8(true); - - try { - mSuccess = false; - mFinished = false; - - // _consoleInfo.get("arguments") is a hashtable of key/value pairs - // to use as the arguments to the CGI - Hashtable args = (Hashtable)_consoleInfo.get("arguments"); - ByteArrayInputStream data = null; - if (args != null && !args.isEmpty()) - data = encode(args); - Debug.println( "Posting " + fullCmd ); - // tell the http manager to notify us immediately of replies - // if we're using async mode - int flags = 0; - - if (mForceBasicAuth) { - flags |= CommManager.FORCE_BASIC_AUTH; - } - - if (data == null) - h.post(new URL(fullCmd), this, null, null, 0, - flags); - else - h.post(new URL(fullCmd), this, null, data, data.available(), - flags); - awaitSuccess(); - Debug.println( "Command executed: " + fullCmd ); - } catch (Exception e) { - if ( e instanceof java.net.ConnectException ) { - CMSAdminUtil.showMessageDialog(mResource, - PREFIX, "SERVERDOWN", CMSAdminUtil.ERROR_MESSAGE); - } - Debug.println( "Command " + fullCmd + " failed: " + e ); - } - return mSuccess; - } - - /** - * waiting for the http transaction to be finished. - */ - public synchronized void awaitSuccess() { - while (!mFinished) { - try {wait();} - catch (Exception e) { } - } - } - - /** - * http transaction finished, notify the process - */ - public synchronized void finish() { - mFinished = true; - notifyAll(); - } - - /** - * the operation is finished after we receive the http stream - */ - public void replyHandler(InputStream response, CommRecord cr) { -/* - try { - int nBytes = response.available(); - if ( nBytes > 0 ) { - // the response from the DS CGIs will typically be in - // UTF8 encoding - byte[] data = new byte[nBytes]; - nBytes = response.read( data ); - mReply = new String( data, 0, nBytes, "UTF8" ); - Debug.println( "CGITask.replyHandler: Response (" + nBytes + - " bytes) = " + mReply ); - int index = 0; - if ((mReply.indexOf("NMC_") != -1) && - ((index = mReply.indexOf(":")) != -1)) { - String sName = mReply.substring(0, index).trim(); - String sValue = mReply.substring(index+1).trim(); - if (sName.equalsIgnoreCase("NMC_Status")) { - int code = Integer.parseInt(sValue); - mSuccess = (code == 0); - } else if (sName.equalsIgnoreCase("NMC_ERRINFO")) { - mErrorMsg = sValue; - } else if (sName.equalsIgnoreCase("NMC_WARNINFO")) { - mWarnMsg = sValue; - } - } - } - } catch ( Exception e ) { - Debug.println( "CGITask.replyHandler: " + e.toString() ); - mSuccess = false; - } - finish(); -*/ - - try { - BufferedReader rspStream = - new BufferedReader(new InputStreamReader(response, "UTF8")); - String rspStr; - - Debug.println("replyHandler() - start"); - while ((rspStr = rspStream.readLine()) != null) - { - Debug.println("replyHandler() - read [" + rspStr + "]"); - // NMC_ messages are parsed, but not shown to the user - /* - if (_statusText != null && !rspStr.startsWith("NMC_")) { - _statusText.append(rspStr + "\n"); - Thread.yield(); // allow graphics repaints - } - */ - Debug.println("Start parsing"); - parse(rspStr); - } - } catch (Exception e) { - Debug.println("ConfigCert.Exception : " + e.toString()); - } - - Debug.println("ConfigCert.replyHandler: finished, mSuccess=" + - mSuccess); - - finish(); - } - - /** - * return the value for the given keyword in the reply - */ - private void parse(String s) { - String sName; - String sValue; - int iIndex; - - Debug.println("Parse input: " + s); - - if ((iIndex=s.indexOf(":")) != (-1)) - { - sName = s.substring(0, iIndex).trim(); - sValue = s.substring(iIndex+1).trim(); - Debug.println("Parse input: name=" + sName + " value=" + sValue); - //mWizardInfo.put(sName, sValue); -/* - if (mCgiResponse == null) - mCgiResponse = new Hashtable(); - mCgiResponse.put(sName, sValue); -*/ - if (sName.equalsIgnoreCase("NMC_Status")) - { - int code = Integer.parseInt(sValue); - mSuccess = (code == 0); - Debug.println("Parse input: code=" + code + " mSuccess=" + - mSuccess); - } else if (sName.equalsIgnoreCase("NMC_ERRINFO")) { - mErrorMsg = sValue; - } else if (sName.equalsIgnoreCase("NMC_WARNINFO")) { - mWarnMsg = sValue; - } - } - - Debug.println("Parse finished"); - } - - public String getErrorMessage() { - return mErrorMsg; - } - - /** - * this function will be called if error occurs - */ - public void errorHandler(Exception error, CommRecord cr) { - Debug.println("CGITask.errorHandler: " + error ); - - mSuccess = false; - finish(); - } - - - public String getDN() { - return _consoleInfo.getCurrentDN(); - } - - public String getReply() { - return mReply; - } - - /** - * Return the command, which should have been stored in the info. - */ - private String getCommand() { - String s = (String)_consoleInfo.get( "execref" ); - if ( s != null ) - return "bin/" + s; - return null; - } - - /** - * pass the username to the admin server - */ - public String username(Object authObject, CommRecord cr) { - Debug.println( "username = " + - (String)_consoleInfo.getAuthenticationDN()); - return _consoleInfo.getAuthenticationDN(); - } - - /** - * pass the user password to the admin server - */ - public String password(Object authObject, CommRecord cr) { - Debug.println( "password = " + - (String)_consoleInfo.get( "AdminUserPassword" ) ); - return (String)_consoleInfo.get( "AdminUserPassword" ); - } - -/* - protected void showDialog( JFrame frame, String msg, String item, - boolean error ) { - // display a message - if ( error ) { - DSUtil.showErrorDialog( frame, msg, item, "dirtask" ); - } else { - DSUtil.showInformationDialog( frame, msg, item, "dirtask" ); - } - } - - protected void showResultDialog( boolean success ) { - // popup a dialog - if ( success ) { - showDialog( new JFrame(), mSection+"-success", "", - false ); - } else { - showDialog( new JFrame(), mSection+"-failed", "", - true ); - } - } - - protected void showResultDialog( int errorCode, String arg ) { - // popup a dialog - String error = "error-" + Integer.toString( errorCode ) + "-msg"; - String title = mSection + "-failed-title"; - DSUtil.showErrorDialog( null, - title, - error, - arg, "dirtask" ); - } - - protected void showResultDialog( CGIThread thread ) { - CGIReportTask task = thread.getTask(); - if ( task.getStatus() != 0 ) { - showResultDialog( task.getStatus(), - (String)task.getResult("NMC_ErrInfo") ); - } else { - showResultDialog( task.getStatus() == 0 ); - } - } - */ - - /** - * Translates a hashtable into <code>x-www-form-urlencoded</code> format. - * Values are converted from Unicode to UTF8 before URL encoding. - * - * @param args <code>Hashtable</code> containing name/value pairs to be translated. - * @return a ByteArrayInputStream to the translated <code>Hashtable</code> contents. - */ - public static ByteArrayInputStream encode(Hashtable args) - { - if ((args == null) || (args.size() == 0)) - return (null); - - String p = ""; - Enumeration e = args.keys(); - - while (e.hasMoreElements()) - { - String name = (String)e.nextElement(); - String value = URLByteEncoder.encodeUTF8(args.get(name).toString()); - Debug.println("********** Encoding name --> "+name+" value --> "+value); - p += URLByteEncoder.encodeUTF8(name) + "=" + - value + (e.hasMoreElements()?"&":""); - } - - return new ByteArrayInputStream(p.getBytes()); - } - -} diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSCertRequest.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSCertRequest.java deleted file mode 100644 index bf391c4e4..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSCertRequest.java +++ /dev/null @@ -1,418 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.keycert.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import com.netscape.management.client.console.*; -import com.netscape.management.client.topology.*; -import com.netscape.management.client.comm.*; -import java.net.*; -import java.io.*; -import netscape.ldap.*; -import netscape.ldap.util.*; - -/** - * Perform certificate request in certificate setup wizard. - * - * @author Michelle Zhao - * @version $Revision$, $Date$ - */ -public class CMSCertRequest extends CGITask { - - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "CGITASK"; - private String mCgiTask = null; // CGI task to call - private CertSetupWizardInfo mWizardInfo; - private String mPolicyMsg = null; - - /*========================================================== - * constructors - *==========================================================*/ - public CMSCertRequest() { - super(); - } - - /*========================================================== - * public methods - *==========================================================*/ - public void initialize(CertSetupWizardInfo info) { - Debug.println("CMSRequestCert: initialize()"); - _consoleInfo = info.getAdminConsoleInfo(); - - // the results coming back from the daemon will be added to the - // wizard information. - mWizardInfo = info; - } - - /** - * Collect the data in name value pairs format and then send them to the - * cgi process. - */ - public boolean requestCert(Hashtable data) { - boolean status = false; // return value - - try { - status = run(data); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSRequestCert: requestCert() after run status=" + - status + " mSuccess=" + mSuccess); - - return mSuccess; - } - - /** - * the operation is finished after we receive the http stream - */ - public void replyHandler(InputStream response, CommRecord cr) { - mSuccess = false; - - try { - BufferedReader rspStream = - new BufferedReader(new InputStreamReader(response, "UTF8")); - String rspStr; - - Debug.println("CMSRequestCert: replyHandler() - start"); - mErrorMsg = mResource.getString("REQUESTRESULTWIZARD_TEXT_ERRORDESC_LABEL"); - while ((rspStr = rspStream.readLine()) != null && !mSuccess) - { - Debug.println("RequestCert: replyHandler() - read [" + rspStr + "]"); - // NMC_ messages are parsed, but not shown to the user - parse2(rspStr); - } - mErrorMsg = mErrorMsg + - mResource.getString("REQUESTRESULTWIZARD_TEXT_ERROREND_LABEL"); - String requestStatus =mWizardInfo.getRequestStatus(); - if ((mWizardInfo.getRequestError() != null) && - mWizardInfo.getRequestError().equals("true")) { - mWizardInfo.setRequestError(mErrorMsg); - mErrorMsg = null; - mSuccess = true; - } else if (requestStatus == null) { - // agent port, Unauthorizied access - mErrorMsg = mResource.getString("CGITASK_DIALOG_WRONGSERVER_MESSAGE"); - } else if (requestStatus.equals("5")) { - // rejected - if (mPolicyMsg == null) { - mWizardInfo.setRequestError(mResource.getString("REQUESTRESULTWIZARD_TEXT_NODETAIL_LABEL")); - } else { - mWizardInfo.setRequestError(mPolicyMsg); - mPolicyMsg = null; - } - mSuccess = true; - } - // Use the same format for other status:success,pending,svcPending - } catch (Exception e) { - Debug.println("RequestCert.Exception : " + e.toString()); - } - - Debug.println("RequestCert.replyHandler: finished, mSuccess=" + - mSuccess); - - finish(); - } - - private void parse2(String s) - { - int iIndex; - Debug.println("Parse2 input: " + s); - if ((iIndex=s.indexOf("errorCode")) != (-1)) - { - String errorCode = s.substring(s.indexOf("\"") + 1, - s.lastIndexOf("\"")); - Debug.println("errorCode: " + errorCode); - if (errorCode.equals("2")) { // pending - mWizardInfo.setRequestError("false"); - mSuccess = true; - mWizardInfo.setRequestStatus("0"); - } else if (errorCode.equals("1")) { // error - mWizardInfo.setRequestError("true"); - mWizardInfo.setRequestStatus("5"); - mSuccess = false; - } else { - mWizardInfo.setRequestError("true"); - mWizardInfo.setRequestStatus("0"); - mSuccess = false; - } - } - else if ((iIndex=s.indexOf("requestList.requestId")) != (-1)) - { - String requestId = s.substring(s.indexOf("\"") + 1, - s.lastIndexOf("\"")); - Debug.println("requestId: " + requestId); - mWizardInfo.setRequestID(requestId); - } - else if ((iIndex=s.indexOf("errorReason")) != (-1)) - { - String errorReason = s.substring(s.indexOf("\"") + 1, - s.lastIndexOf("\"")); - Debug.println("errorReason: " + errorReason); - mErrorMsg = mErrorMsg + "\n " + errorReason; - } - } - - /** - * return the value for the given keyword in the reply - */ - private void parse(String s) { - String sName; - String sValue = null; - int iIndex; - - Debug.println("Parse input: " + s); - - // XXXX We need to know all possible response. - // If cmsgateway changes, this will be broken. - if ((iIndex=s.indexOf("requestStatus = ")) != (-1)) - { - sName = s.substring(iIndex + 17).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mWizardInfo.setRequestStatus(sValue); - if (sValue.equals("2") || sValue.equals("3") - || sValue.equals("4")) - // success, pending, svcPending - mSuccess = true; - } - } - else if ((iIndex=s.indexOf("requestId = ")) != (-1)) - { - sName = s.substring(iIndex + 13).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mWizardInfo.setRequestID(sValue); - //mSuccess = true; - } - } - else if ((iIndex=s.indexOf("unexpectedError = ")) != (-1)) - { - sName = s.substring(iIndex + 19).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - mWizardInfo.setRequestError("true"); - } - } - else if ((iIndex=s.indexOf("errorDetails = ")) != (-1)) - { - sName = s.substring(iIndex + 16).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - mWizardInfo.setRequestError("true"); - } - } - else if ((iIndex=s.indexOf("result.recordSet.length = ")) != (-1)) - { - sName = s.substring(iIndex + 27).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("") && !sValue.equals("0")) { - mErrorMsg = mErrorMsg + mResource.getString("REQUESTRESULTWIZARD_TEXT_DETAIL_LABEL");; - } - } - else if ((iIndex=s.indexOf("errorDescription = ")) != (-1)) - { - sName = s.substring(iIndex + 20).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - } - } - else if ((iIndex=s.indexOf("record.policyMessage=")) != (-1)) - { - sName = s.substring(iIndex + 22).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - if (mPolicyMsg == null) - mPolicyMsg = " " + sValue; - else - mPolicyMsg = mPolicyMsg + "\n " + sValue; - } - } - - Debug.println("Parse finished"); - } - - /** - * Send an http request to the server. Return true if we're sure it - * succeeded, otherwise false. - */ - boolean run(Hashtable args) { - - String fullCmd = mWizardInfo.getCMEEType() + "://" + - mWizardInfo.getCMHost() + ":" + - mWizardInfo.getCMEEPort() + "/ca/ee/ca/profileSubmit"; - - HttpManager h = new HttpManager(); - // tell the http manager to use UTF8 encoding - h.setSendUTF8(true); - - try { - mSuccess = false; - mFinished = false; - - ByteArrayInputStream data = null; - if (args != null && !args.isEmpty()) - data = encode(args); - Debug.println( "Posting " + fullCmd ); - // tell the http manager to notify us immediately of replies - // if we're using async mode - int flags = 0; - CommRecord postResult = null; - if (data == null) - postResult = h.post(new URL(fullCmd), this, null, null, 0, - flags); - else - postResult = h.post(new URL(fullCmd), this, null, data, data.available(), - flags); - - /* - AdmTask admTask = new AdmTask(new URL(fullCmd),null,null); - admTask.setArguments(args); - admTask.exec(h); - */ - - awaitSuccess(); - - Object postStatus = postResult.getStatus(); - //Debug.println("status: " + postStatus); - if (postStatus != null && - postStatus.toString().equals(CommRecord.ERROR)) { - // If it happens to be it's not CMS server who is listening - // e.g. the cms agent port or yahoo server - // you may get here - mErrorMsg = mResource.getString("CGITASK_DIALOG_WRONGSERVER_MESSAGE"); - } - - Debug.println( "Command executed: " + fullCmd ); - } catch (Exception e) { - // This is very fragile. We have to handle it case by case. - // Handled the ones that I know of properly, but there may - // be other cases that I don't know, display the exception - // detail. - String detail = e.toString(); - if (detail == null || detail.trim().equals("")) - detail = "No detail of the exception provided."; - if ( e instanceof java.net.ConnectException ) { - mErrorMsg = mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE"); - //CMSAdminUtil.showMessageDialog(mResource, - // PREFIX, "CMSDOWN", CMSAdminUtil.ERROR_MESSAGE); - } else if ( e instanceof java.net.NoRouteToHostException ) { - // java.net.NoRouteToHostException: Connection timed out - // It takes 3-4 mins to time out, looks like hang to impatient - // ones. https://www.netscape.com:443 - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -; - } else if ( e instanceof java.net.SocketException ) { - if (detail.indexOf("Socket write failed") > -1){ - // retry - run(args); - } else if ((detail.indexOf("Connection shutdown") > -1) || - (detail.indexOf("Connection timed out") > -1) ) { - // java.net.NoRouteToHostException: Connection timed out - // double insurance - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE"); - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE")+ " java.net.SocketException: " + detail; - } - - } else if ( e instanceof java.io.IOException ) { - if (e.toString().indexOf("Broken pipe") > -1){ - // broken pipe, retry - run(args); - } else if (detail.indexOf("Unknown public-key algorithm") -> -1) { - mErrorMsg = - mResource.getString("CGITASK_DIALOG_UNKNOWNALG_MESSAGE") -; - } else if (detail.indexOf("End of input") > -1) { - // http://www.netscape.com:80/enrollment - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -; - } else if (detail.indexOf("Certificate fingerprint =") > -1) { - // reject the cms certificate - mErrorMsg = - mResource.getString("CGITASK_DIALOG_REJECTCERT_MESSAGE"); - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE" -) + " java.io.IOException: " + detail; - } - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -+ " Exception: " + detail; - } - Debug.println( "Command " + fullCmd + " failed: " + e ); - } - return mSuccess; - } - -} - - - diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSConfigCert.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSConfigCert.java deleted file mode 100644 index 7d85d161f..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSConfigCert.java +++ /dev/null @@ -1,207 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.config.install.*; -import com.netscape.admin.certsrv.wizard.WizardBasePanel; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import com.netscape.management.client.console.*; -import com.netscape.management.client.topology.*; -import com.netscape.management.client.comm.*; -import java.net.*; -import java.io.*; -import netscape.ldap.*; -import netscape.ldap.util.*; - -/** - * Perform certificate server configuration. - * - * @author Christine Ho - * @version $Revision$, $Date$ - */ -public class CMSConfigCert extends CGITask { - - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "CMSCONFIGCERT"; - - public static final String CONFIG_CERT_CGI = "Tasks/Operation/config-cert"; - - //private boolean mSuccess = false; // status of last executed CGI - //private Hashtable mCgiResponse = null; // holds parsed contents of CGI return - private String mCgiTask = null; // CGI task to call - private InstallWizardInfo mWizardInfo; - - /*========================================================== - * constructors - *==========================================================*/ - public CMSConfigCert() { - super(); - } - - /*========================================================== - * public methods - *==========================================================*/ - public void initialize(InstallWizardInfo info) { - _consoleInfo = info.getAdminConsoleInfo(); - - // the results coming back from the daemon will be added to the - // wizard information. - mWizardInfo = info; - - setForceBasicAuth(true); - } - - /** - * Collect the data in name value pairs format and then send them to the - * cgi process. - */ - public boolean configCert(Hashtable data) { - JFrame mActiveFrame = UtilConsoleGlobals.getActivatedFrame(); - if (_consoleInfo.get("AdminUsername") == null) - _consoleInfo.put("AdminUsername", _consoleInfo.getAuthenticationDN()); - Debug.println("AdminUsername = " + _consoleInfo.get("AdminUsername")); - - if (_consoleInfo.get("AdminUserPassword") == null) - _consoleInfo.put("AdminUserPassword", - _consoleInfo.getAuthenticationPassword()); - Debug.println("AdminUserPassword = " + _consoleInfo.get("AdminUserPassword")); - data.put("AdminUserPassword", _consoleInfo.getAuthenticationPassword()); - _consoleInfo.put("arguments", data); - - // Send Random value for RNG entropy - data.put(ConfigConstants.PR_CMS_SEED, new Long(WizardBasePanel.mSeed).toString()); - - boolean status = false; // return value - - Cursor cursor = mActiveFrame.getCursor(); - int type = cursor.getType(); - cursor = new Cursor(Cursor.WAIT_CURSOR); - mActiveFrame.setCursor(cursor); - - try { - status = super.run(null, CONFIG_CERT_CGI); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSConfigCert: configCert() after run status=" + - status + " mSuccess=" + mSuccess); - - if (!mSuccess) { - Debug.println("Show error dialog"); - String errorMsg = getErrorMessage(); -/* - if (errorMsg == null || errorMsg.equals("")) - CMSAdminUtil.showMessageDialog(mActiveFrame, mResource, PREFIX, - "SYSTEMERROR", CMSAdminUtil.ERROR_MESSAGE); - else - JOptionPane.showMessageDialog(mActiveFrame, errorMsg, - "Error", CMSAdminUtil.ERROR_MESSAGE, - CMSAdminUtil.getImage(CMSAdminResources.IMAGE_ERROR_ICON)); -*/ - } - - cursor = new Cursor(type); - mActiveFrame.setCursor(cursor); - - return mSuccess; - } - - /** - * the operation is finished after we receive the http stream - */ - public void replyHandler(InputStream response, CommRecord cr) { - mSuccess = false; -/* - if (mCgiResponse != null) - mCgiResponse.clear(); -*/ - - try { - BufferedReader rspStream = - new BufferedReader(new InputStreamReader(response, "UTF8")); - String rspStr; - - Debug.println("CMSConfigCert: replyHandler() - start"); - while ((rspStr = rspStream.readLine()) != null) - { - Debug.println("ConfigCert: replyHandler() - read [" + rspStr + "]"); - // NMC_ messages are parsed, but not shown to the user - /* - if (_statusText != null && !rspStr.startsWith("NMC_")) { - _statusText.append(rspStr + "\n"); - Thread.yield(); // allow graphics repaints - } - */ - parse(rspStr); - } - } catch (Exception e) { - Debug.println("ConfigCert.Exception : " + e.toString()); - } - - Debug.println("ConfigCert.replyHandler: finished, mSuccess=" + - mSuccess); - - finish(); - } - - /** - * return the value for the given keyword in the reply - */ - private void parse(String s) { - String sName; - String sValue; - int iIndex; - - Debug.println("Parse input: " + s); - - if ((iIndex=s.indexOf(":")) != (-1)) - { - sName = s.substring(0, iIndex).trim(); - sValue = s.substring(iIndex+1).trim(); - Debug.println("Parse input: name=" + sName + " value=" + sValue); - mWizardInfo.put(sName, sValue); -/* - if (mCgiResponse == null) - mCgiResponse = new Hashtable(); - mCgiResponse.put(sName, sValue); -*/ - if (sName.equalsIgnoreCase("NMC_Status")) - { - int code = Integer.parseInt(sValue); - mSuccess = (code == 0); - Debug.println("Parse input: code=" + code + " mSuccess=" + mSuccess); - } else if (sName.equalsIgnoreCase("NMC_ERRINFO")) - mErrorMsg = sValue; - Debug.println("ErrorMsg : " + mErrorMsg); - } - - Debug.println("Parse finished"); - } -} diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSImportCert.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSImportCert.java deleted file mode 100644 index b285b2284..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSImportCert.java +++ /dev/null @@ -1,429 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.config.install.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import com.netscape.management.client.console.*; -import com.netscape.management.client.topology.*; -import com.netscape.management.client.comm.*; -import java.net.*; -import java.io.*; -import netscape.ldap.*; -import netscape.ldap.util.*; - -/** - * Perform certificate import. - * - * @author Michelle Zhao - * @version $Revision$, $Date$ - */ -public class CMSImportCert extends CGITask { - - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "CGITASK"; - private String mCgiTask = null; // CGI task to call - private InstallWizardInfo mWizardInfo; - private String mPolicyMsg = null; - - // To support Thawte's header and footer - public static final String BEGIN_PKCS7_HEADER = - "-----BEGIN PKCS #7 SIGNED DATA-----"; - public static final String END_PKCS7_HEADER = - "-----END PKCS #7 SIGNED DATA-----"; - public static final String BEGIN_HEADER = "-----BEGIN CERTIFICATE-----"; - public static final String END_HEADER = "-----END CERTIFICATE-----"; - - /*========================================================== - * constructors - *==========================================================*/ - public CMSImportCert() { - super(); - } - - /*========================================================== - * public methods - *==========================================================*/ - public void initialize(InstallWizardInfo info) { - Debug.println("CMSImportCert: initialize()"); - _consoleInfo = info.getAdminConsoleInfo(); - - // the results coming back from the daemon will be added to the - // wizard information. - mWizardInfo = info; - } - - /** - * Collect the data in name value pairs format and then send them to the - * cgi process. - */ - public boolean importCert(Hashtable data) { - boolean status = false; // return value - - try { - status = run(data); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSImportCert: ImportCert() after run status=" + - status + " mSuccess=" + mSuccess); - - return mSuccess; - } - - /** - * the operation is finished after we receive the http stream - */ - public void replyHandler(InputStream response, CommRecord cr) { - mSuccess = false; - - try { - BufferedReader rspStream = - new BufferedReader(new InputStreamReader(response, "UTF8")); - String rspStr; - - Debug.println("CMSImportCert: replyHandler() - start"); - - mWizardInfo.setImportError(""); - while ((rspStr = rspStream.readLine()) != null && !mSuccess) - { - Debug.println("ImportCert: replyHandler() - read [" + rspStr + "]"); - // NMC_ messages are parsed, but not shown to the user - parse(rspStr); - } - - String importError = mWizardInfo.getImportError(); - if (importError != null && !importError.equals("")) { - mErrorMsg = importError; - mSuccess = false; - } else if (!mSuccess) { - // agent port, Unauthorizied access - mErrorMsg = mResource.getString("CGITASK_DIALOG_WRONGSERVER_MESSAGE"); - } - } catch (Exception e) { - Debug.println("ImportCert.Exception : " + e.toString()); - } - - Debug.println("ImportCert.replyHandler: finished, mSuccess=" + - mSuccess); - - finish(); - } - - /** - * return the value for the given keyword in the reply - */ - private void parse(String s) { - String sName; - String sValue = null; - int iIndex; - - Debug.println("Parse input: " + s); - - if ((iIndex=s.indexOf("status = ")) != (-1)) - { - sName = s.substring(iIndex + 10).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - if (sValue.equals(ConfigConstants.PENDING_STRING) || - sValue.equals(ConfigConstants.APPROVED_STRING) || - sValue.equals(ConfigConstants.SVC_PENDING_STRING)) { - mWizardInfo.setImportError("Request " + - mWizardInfo.getRequestID() + - " is " + sValue + - ".\nYou can contact an authorized agent or local administrator for further assistance by referring to the request ID."); - mSuccess = true; - } else if (sValue.equals(ConfigConstants.CANCELED_STRING) || - sValue.equals(ConfigConstants.REJECTED_STRING) ) { - String stage = - getStage(mWizardInfo.getCertType()); - if (stage != null) - mWizardInfo.put(stage, ConfigConstants.FALSE); - mWizardInfo.setImportError("Request " + - mWizardInfo.getRequestID() + - " is " + sValue + - ".\nYou can contact an authorized agent or local administrator for further assistance by referring to the request ID." + "\nYou will be able to regenerate a new request if you click back." ); - mSuccess = true; - } - } - } - else if ((iIndex=s.indexOf("pkcs7ChainBase64 = ")) != (-1)) - { - sName = s.substring(iIndex + 20).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - String val = sValue.trim(); - String result = normalizeCertStr(val); - Debug.println("After removing all the carriage returns:"); - Debug.println(result); - mWizardInfo.setPKCS10(result); - mSuccess = true; - - } - } - else if ((iIndex=s.indexOf("unexpectedError = ")) != (-1)) - { - sName = s.substring(iIndex + 19).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - mWizardInfo.setRequestError("true"); - } - } - else if ((iIndex=s.indexOf("errorDetails = ")) != (-1)) - { - sName = s.substring(iIndex + 16).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - mWizardInfo.setRequestError("true"); - } - } - else if ((iIndex=s.indexOf("result.recordSet.length = ")) != (-1)) - { - sName = s.substring(iIndex + 27).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("") && !sValue.equals("0")) { - mErrorMsg = mErrorMsg + mResource.getString("REQUESTRESULTWIZARD_TEXT_DETAIL_LABEL");; - } - } - else if ((iIndex=s.indexOf("errorDescription = ")) != (-1)) - { - sName = s.substring(iIndex + 20).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - } - } - else if ((iIndex=s.indexOf("record.policyMessage=")) != (-1)) - { - sName = s.substring(iIndex + 22).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - if (mPolicyMsg == null) - mPolicyMsg = " " + sValue; - else - mPolicyMsg = mPolicyMsg + "\n " + sValue; - } - } - - Debug.println("Parse finished"); - } - - /** - * Send an http request to the server. Return true if we're sure it - * succeeded, otherwise false. - */ - boolean run(Hashtable args) { - - String fullCmd = mWizardInfo.getCMEEType() + "://" + - mWizardInfo.getCMHost() + ":" + - mWizardInfo.getCMEEPort() + "/checkRequest"; - - HttpManager h = new HttpManager(); - // tell the http manager to use UTF8 encoding - h.setSendUTF8(true); - - try { - mSuccess = false; - mFinished = false; - - ByteArrayInputStream data = null; - if (args != null && !args.isEmpty()) - data = encode(args); - Debug.println( "Posting " + fullCmd ); - // tell the http manager to notify us immediately of replies - // if we're using async mode - int flags = 0; - CommRecord postResult = null; - if (data == null) - postResult = h.post(new URL(fullCmd), this, null, null, 0, - flags); - else - postResult = h.post(new URL(fullCmd), this, null, data, data.available(), - flags); - - /* - AdmTask admTask = new AdmTask(new URL(fullCmd),null,null); - admTask.setArguments(args); - admTask.exec(h); - */ - - awaitSuccess(); - - Object postStatus = postResult.getStatus(); - //Debug.println("status: " + postStatus); - if (postStatus != null && - postStatus.toString().equals(CommRecord.ERROR)) { - // If it happens to be it's not CMS server who is listening - // e.g. the cms agent port or yahoo server - // you may get here - mErrorMsg = mResource.getString("CGITASK_DIALOG_WRONGSERVER_MESSAGE"); - } - - Debug.println( "Command executed: " + fullCmd ); - } catch (Exception e) { - // This is very fragile. We have to handle it case by case. - // Handled the ones that I know of properly, but there may - // be other cases that I don't know, display the exception - // detail. - String detail = e.toString(); - if (detail == null || detail.trim().equals("")) - detail = "No detail of the exception provided."; - if ( e instanceof java.net.ConnectException ) { - mErrorMsg = mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE"); - //CMSAdminUtil.showMessageDialog(mResource, - // PREFIX, "CMSDOWN", CMSAdminUtil.ERROR_MESSAGE); - } else if ( e instanceof java.net.NoRouteToHostException ) { - // java.net.NoRouteToHostException: Connection timed out - // It takes 3-4 mins to time out, looks like hang to impatient - // ones. https://www.netscape.com:443 - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -; - } else if ( e instanceof java.net.SocketException ) { - if (detail.indexOf("Socket write failed") > -1){ - // retry - run(args); - } else if ((detail.indexOf("Connection shutdown") > -1) || - (detail.indexOf("Connection timed out") > -1) ) { - // java.net.NoRouteToHostException: Connection timed out - // double insurance - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE"); - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE")+ " java.net.SocketException: " + detail; - } - - } else if ( e instanceof java.io.IOException ) { - if (e.toString().indexOf("Broken pipe") > -1){ - // broken pipe, retry - run(args); - } else if (detail.indexOf("Unknown public-key algorithm") -> -1) { - mErrorMsg = - mResource.getString("CGITASK_DIALOG_UNKNOWNALG_MESSAGE") -; - } else if (detail.indexOf("End of input") > -1) { - // http://www.netscape.com:80/enrollment - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -; - } else if (detail.indexOf("Certificate fingerprint =") > -1) { - // reject the cms certificate - mErrorMsg = - mResource.getString("CGITASK_DIALOG_REJECTCERT_MESSAGE"); - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE" -) + " java.io.IOException: " + detail; - } - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -+ " Exception: " + detail; - } - Debug.println( "Command " + fullCmd + " failed: " + e ); - } - return mSuccess; - } - - String getStage(String reqType){ - if (reqType.equals(Constants.PR_CA_SIGNING_CERT)){ - return ConfigConstants.STAGE_CA_REQ_SUCCESS; - }else if (reqType.equals(Constants.PR_SERVER_CERT)){ - return ConfigConstants.STAGE_SSL_REQ_SUCCESS; - }else if (reqType.equals(Constants.PR_KRA_TRANSPORT_CERT)){ - return ConfigConstants.STAGE_KRA_REQ_SUCCESS; - }else if (reqType.equals(Constants.PR_RA_SIGNING_CERT)){ - return ConfigConstants.STAGE_RA_REQ_SUCCESS; - }else if (reqType.equals(Constants.PR_OCSP_SIGNING_CERT)){ - return ConfigConstants.STAGE_OCSP_REQ_SUCCESS; - }else - return null; - } - - - public static String normalizeCertStr(String s) { - String val = ""; - - for (int i = 0; i < s.length(); i++) { - if (s.charAt(i) == '\n') { - continue; - } else if (s.charAt(i) == '\r') { - continue; - } else if (s.charAt(i) == '\\' && s.charAt(i+1) == 'r') { - i++; - continue; - } else if (s.charAt(i) == '"') { - continue; - } else if (s.charAt(i) == ' ') { - continue; - } - val += s.charAt(i); - } - return val; - } - -} - - diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSMigrateCreate.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSMigrateCreate.java deleted file mode 100644 index c7ff02c36..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSMigrateCreate.java +++ /dev/null @@ -1,340 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.admin.certsrv.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import com.netscape.management.client.console.*; -import com.netscape.management.client.topology.*; -import com.netscape.management.client.comm.*; -import java.net.*; -import java.io.*; -import netscape.ldap.*; -import netscape.ldap.util.*; - -/** - * Create or Migrate the Certificate Server - * - * @author Jack Pan-Chen - * @version $Revision$, $Date$ - */ -public class CMSMigrateCreate extends CGITask - implements IProductObject -{ - - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "CMSMIGRATECREATE"; - - private static final String CREATE_CGI_NAME = "Tasks/Operation/Create"; - - //private boolean mSuccess = false; // status of last executed CGI - private Hashtable mCgiResponse = null; // holds parsed contents of CGI return - private String mCgiTask = null; // CGI task to call - - /*========================================================== - * constructors - *==========================================================*/ - public CMSMigrateCreate() { - super(); - } - - /*========================================================== - * public methods - *==========================================================*/ - public void initialize(ConsoleInfo info) { - Debug.println("CMSMigrateCreate: initialize()"); - _consoleInfo = info; - } - - public boolean migrate(String serverRoot, - String server, - String targetDN, - boolean flag) { - - Debug.println("CMSMigrateCreate: migrate()"); - - return false; - } - - /** - * Starts the server specific creation code, providing the DN for the - * target admin group. The method returns true or false depending - * on whether it was successful. - * - * @param targetDN - the admin group DN where the new instance is to be - * created. - * @return boolean value indicating whether the process succeeded (true) - * or failed (false). - */ - public boolean createNewInstance(String targetDN) { - //Debug.println("CMSMigrateCreate: createNewInstance()- "+targetDN); - //targetDN: cn=Server Group, cn=cynthiar.mcom.com, ou=mcom.com, o=NetscapeRoot - - JFrame mActiveFrame = UtilConsoleGlobals.getActivatedFrame(); - boolean status = false; // return value - //show dialog - CreateInstanceDialog dialog = new CreateInstanceDialog(mActiveFrame); - // UtilConsoleGlobals.getActivatedFrame()); - dialog.show(); - if (dialog.isCancel()) { - return status; - } - - //construct the rest of the configuration parameters - //serverName=cynthiar.mcom.com - //sieURL=ldap://laiking.mcom.com:389/o=netscapeRoot - //adminUID=admin - //adminPWD=admin - //instanceID=cert-data - //serverRoot=/u/thomask/s4 - //adminDomain=mcom.com - - Hashtable configParams = new Hashtable(); - - configParams.put("instanceID",dialog.getInstanceName()); - - String[] entries = LDAPDN.explodeDN(targetDN, false); - String DN = entries[entries.length-3] + ", " + - entries[entries.length-2] + ", " + - entries[entries.length-1]; - - //DN: cn=cynthiar.mcom.com, ou=mcom.com, o=NetscapeRoot - - configParams.put("machineName", getValue(DN, "serverHostName", - LDAPConnection.SCOPE_BASE, null)); - configParams.put("serverRoot", getValue(targetDN, "nsconfigroot", - LDAPConnection.SCOPE_BASE, null)); - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - String ssdn = ldc.getAuthenticationDN(); - String[] avas = LDAPDN.explodeDN(ssdn, false); - String uid = avas[0]; - if (!uid.startsWith("uid")) { - CMSAdminUtil.showMessageDialog(mActiveFrame, - mResource, PREFIX, "RESTARTADMINERROR", - CMSAdminUtil.ERROR_MESSAGE); - return false; - } - configParams.put("adminUID", uid.substring(4,uid.length())); - - configParams.put("adminPWD",ldc.getAuthenticationPassword()); - String ldapUrl = "ldap://" + ldc.getHost() + ":" + - Integer.toString(ldc.getPort()) + "/" + - (String)_consoleInfo.get("BaseDN"); - configParams.put("sieURL", ldapUrl); - - String searchDN = entries[entries.length-2]; - configParams.put("adminDomain", searchDN.substring(3,searchDN.length())); - - Debug.println("CMSMigrateCreate: createNewInstance()- "+configParams.toString()); - - // set the arguments for the CGI call - _consoleInfo.put("arguments", configParams); - _consoleInfo.put(CREATE_CGI_NAME, "cert"); - if (_consoleInfo.get("AdminUsername") == null) - _consoleInfo.put("AdminUsername", _consoleInfo.getAuthenticationDN()); - Debug.println("AdminUsername = " + _consoleInfo.get("AdminUsername")); - - if (_consoleInfo.get("AdminUserPassword") == null) - _consoleInfo.put("AdminUserPassword", - _consoleInfo.getAuthenticationPassword()); - Debug.println("AdminUserPassword = " + _consoleInfo.get("AdminUserPassword")); - - // call the CGI program - Debug.println("CMSMigrateCreate: createNewInstance() before run task="+CREATE_CGI_NAME); - mCgiTask = CREATE_CGI_NAME; - - Cursor cursor = mActiveFrame.getCursor(); - int type = cursor.getType(); - cursor = new Cursor(Cursor.WAIT_CURSOR); - mActiveFrame.setCursor(cursor); - - try { - status = super.run(null, CREATE_CGI_NAME); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - - Debug.println("CMSMigrateCreate: createNewInstance() after run status=" + - status + " mSuccess=" + mSuccess); - - if (!mSuccess) { - Debug.println("Show error dialog"); - String errorMsg = getErrorMessage(); - if (errorMsg == null || errorMsg.equals("")) - CMSAdminUtil.showMessageDialog(mActiveFrame, mResource, PREFIX, - "SYSTEMERROR", CMSAdminUtil.ERROR_MESSAGE); - else - JOptionPane.showMessageDialog(mActiveFrame, errorMsg, - "Error", CMSAdminUtil.ERROR_MESSAGE, - CMSAdminUtil.getImage(CMSAdminResources.IMAGE_ERROR_ICON)); - } - - cursor = new Cursor(type); - mActiveFrame.setCursor(cursor); - - return mSuccess; - } - - /** - * the operation is finished after we receive the http stream - */ - public void replyHandler(InputStream response, CommRecord cr) { - mSuccess = false; - if (mCgiResponse != null) - mCgiResponse.clear(); - - try { - BufferedReader rspStream = - new BufferedReader(new InputStreamReader(response, "UTF8")); - String rspStr; - - Debug.println("CMSMigrateCreate: replyHandler() - start"); - while ((rspStr = rspStream.readLine()) != null) - { - Debug.println("CMSMigrateCreate: replyHandler() - read [" + rspStr + "]"); - // NMC_ messages are parsed, but not shown to the user - /* - if (_statusText != null && !rspStr.startsWith("NMC_")) { - _statusText.append(rspStr + "\n"); - Thread.yield(); // allow graphics repaints - } - */ - parse(rspStr); - } - } catch (Exception e) { - Debug.println("MigrateCreate.replyHandler: " + e.toString()); - } - - Debug.println("MigrateCreate.replyHandler: finished, mSuccess=" + - mSuccess); - - finish(); - } - - /** - * return the value for the given keyword in the reply - */ - private void parse(String s) { - String sName; - String sValue; - int iIndex; - - Debug.println("Parse input: " + s); - - if ((iIndex=s.indexOf(":")) != (-1)) - { - sName = s.substring(0, iIndex).trim(); - sValue = s.substring(iIndex+1).trim(); - Debug.println("Parse input: name=" + sName + " value=" + sValue); - if (mCgiResponse == null) - mCgiResponse = new Hashtable(); - mCgiResponse.put(sName, sValue); - if (sName.equalsIgnoreCase("NMC_Status")) { - int code = Integer.parseInt(sValue); - mSuccess = (code == 0); - Debug.println("Parse input: code=" + code + " mSuccess=" + mSuccess); - } else if (sName.equalsIgnoreCase("NMC_ERRINFO")) { - mErrorMsg = sValue; - } - } - - Debug.println("Parse finished"); - } - - /** - * Get one value for one specified attribute from the given DN. - * If there is more than 1 entry which matches the given criteria, the - * first one will be used. - * - * @param DN DN of the entry with the specified attributes - * @param attr Attribute to get the value of - * @param scope LDAPConnection SCOPE_BASE SCOPE_ONE SCOPE_SUB - * @param filter LDAP search filter; if null, default is objectclass=* - * @return The string value of the attribute; multi-valued - * attributes are returned as 1 value, space delimited - * (flattened) - **/ - protected String getValue(String DN, String attr, int scope, - String filter) { - String[] attrs = { attr }; - String[] values = getValues(DN, attrs, scope, filter); - if (values != null) - return values[0]; - - return null; - } - - /** - * Get the values for several specified attributes from the given DN. - * If there is more than 1 entry which matches the given criteria, the - * first one will be used. - * - * @param DN DN of the entry with the specified attributes - * @param attrs Array of attributes to get the values of - * @param scope LDAPConnection SCOPE_BASE SCOPE_ONE SCOPE_SUB - * @param filter LDAP search filter; if null, default is objectclass=* - * @return An array of string values for each attribute; multi-valued - * attributes are returned as 1 value, space delimited - * (flattened) - **/ - protected String[] getValues(String DN, String[] attrs, int scope, - String filter) { - String[] values = null; - LDAPSearchResults results = null; - if (filter == null) - filter = "(objectclass=*)"; - - try { - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - if (ldc != null) - { - results = ldc.search(DN, scope, filter, attrs, false); - } - } catch (LDAPException e) { - Debug.println("error MigrateCreate.getValues: LDAP read failed " + - "for DN=" + DN + " attributes " + attrs); - Debug.println("error MigrateCreate.getValues: LDAP Exception:" + - e); - } - - if (results != null && results.hasMoreElements()) { - values = new String[attrs.length]; - LDAPEntry entry = (LDAPEntry)results.nextElement(); - for (int ii = 0; entry != null && ii < attrs.length; ++ii) { - values[ii] = LDAPUtil.flatting(entry.getAttribute(attrs[ii])); - } - } else { - Debug.println("error MigrateCreate.getValues: LDAP read failed " + - "for DN=" + DN + " attributes=" + attrs); - } - - return values; - } - -} diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRemove.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRemove.java deleted file mode 100644 index 57473c5e0..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRemove.java +++ /dev/null @@ -1,166 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.management.client.console.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.connection.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import netscape.ldap.*; - -/** - * Remove the server - * - * @author Jack Pan-Chen - * @version $Revision$, $Date$ - */ -public class CMSRemove extends CGITask -{ - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "TASKREMOVE"; - public static final String REMOVE_TASK_CGI = "Tasks/Operation/remove"; - private Hashtable mCgiResponse = null; - private String mCgiTask = null; - - /*========================================================== - * constructors - *==========================================================*/ - - public CMSRemove() { - super(); - setName(mResource.getString(PREFIX+"_REMOVE_LABEL")); - setDescription(mResource.getString(PREFIX+"_REMOVE_DESC")); - } - - public void initialize(ConsoleInfo info) { - Debug.println("CMSRemove: initialize()"); - _consoleInfo = info; - } - - /*========================================================== - * public methods - *==========================================================*/ - public boolean run(IPage viewInstance) - { - Debug.println("CMSRemove: run()"); - boolean status = false; // return value - Hashtable configParams = new Hashtable(); - configParams.put("serverRoot",_consoleInfo.get("serverRoot")); - String servid = (String)_consoleInfo.get("servid"); - int index = servid.indexOf("-"); - if (index != -1) { - servid = servid.substring(index+1); - } - configParams.put("instanceID", servid); - - // get the CMS instance host and port - servid = (String)_consoleInfo.get("servid"); - String configDN = _consoleInfo.getCurrentDN(); - - try { - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - if (ldc == null) { - ldc = new LDAPConnection(); - } - if (ldc.isConnected() == false) { - ldc.connect(_consoleInfo.getHost(), _consoleInfo.getPort(), - _consoleInfo.getAuthenticationDN(), - _consoleInfo.getAuthenticationPassword()); - } - LDAPEntry entry = ldc.read(configDN); - String cmsHost = LDAPUtil.flatting( - entry.getAttribute("serverHostName", - LDAPUtil.getLDAPAttributeLocale())); - String cmsPort = LDAPUtil.flatting( - entry.getAttribute("nsServerPort", - LDAPUtil.getLDAPAttributeLocale())); - - Debug.println("host:" + cmsHost+" port:"+cmsPort); - configParams.put("cmsHost", cmsHost); - configParams.put("cmsPort", cmsPort); - } - catch (LDAPException e) { - Debug.println( - "ERROR CMSRemove: LDAP read failed: " + - configDN); - } - _consoleInfo.put("arguments", configParams); - - String authdn = _consoleInfo.getAuthenticationDN(); - - if (_consoleInfo.get("AdminUsername") == null) - _consoleInfo.put("AdminUsername", authdn); - - if (!authdn.startsWith("uid")) { - JFrame mActiveFrame = UtilConsoleGlobals.getActivatedFrame(); - CMSAdminUtil.showMessageDialog(mActiveFrame, - mResource, PREFIX, "RESTARTADMINERROR", - CMSAdminUtil.ERROR_MESSAGE); - return false; - } - - Debug.println("AdminUsername = " + _consoleInfo.get("AdminUsername")); - - if (_consoleInfo.get("AdminUserPassword") == null) - _consoleInfo.put("AdminUserPassword", - _consoleInfo.getAuthenticationPassword()); - Debug.println("AdminUserPassword = " + _consoleInfo.get("AdminUserPassword")); - // call the CGI program - Debug.println("CMSRemove: remove() before run task="+REMOVE_TASK_CGI); - try { - status = super.run(null, REMOVE_TASK_CGI); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSRemove: remove() after run status="+status); - - String title = mResource.getString("REMOVERESULTDIALOG_TITLE"); - - if (!status) { - Debug.println("Show error dialog"); - // if no error message from the server, then just show the generic - // error message. - if (mErrorMsg.equals("")) - CMSAdminUtil.showMessageDialog( - UtilConsoleGlobals.getActivatedFrame(), - mResource, PREFIX, "SYSTEMERROR", CMSAdminUtil.ERROR_MESSAGE); - else { - String errorMsg = - mResource.getString("REMOVERESULTDIALOG_FAILED_TEXT")+mErrorMsg; - Icon icon = CMSAdminUtil.getImage(CMSAdminResources.IMAGE_ERROR_ICON); - JOptionPane.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), - errorMsg, title, JOptionPane.ERROR_MESSAGE, icon); - } - } else { - Debug.println("Successful operation"); - String msg = mResource.getString("REMOVERESULTDIALOG_SUCCESS_TEXT"); - Icon icon = CMSAdminUtil.getImage(CMSAdminResources.IMAGE_INFO_ICON); - JOptionPane.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), - msg, title, JOptionPane.INFORMATION_MESSAGE, icon); - } - return status; - } -} - diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRequestCert.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRequestCert.java deleted file mode 100644 index 8b3cfef6b..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRequestCert.java +++ /dev/null @@ -1,421 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.config.install.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import com.netscape.management.client.console.*; -import com.netscape.management.client.topology.*; -import com.netscape.management.client.comm.*; -import java.net.*; -import java.io.*; -import netscape.ldap.*; -import netscape.ldap.util.*; - -/** - * Perform certificate request. - * - * @author Michelle Zhao - * @version $Revision$, $Date$ - */ -public class CMSRequestCert extends CGITask { - - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "CGITASK"; - private String mCgiTask = null; // CGI task to call - private InstallWizardInfo mWizardInfo; - private String mPolicyMsg = null; - - /*========================================================== - * constructors - *==========================================================*/ - public CMSRequestCert() { - super(); - } - - /*========================================================== - * public methods - *==========================================================*/ - public void initialize(InstallWizardInfo info) { - Debug.println("CMSRequestCert: initialize()"); - _consoleInfo = info.getAdminConsoleInfo(); - - // the results coming back from the daemon will be added to the - // wizard information. - mWizardInfo = info; - } - - /** - * Collect the data in name value pairs format and then send them to the - * cgi process. - */ - public boolean requestCert(Hashtable data) { - boolean status = false; // return value - - try { - status = run(data); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSRequestCert: requestCert() after run status=" + - status + " mSuccess=" + mSuccess); - - return mSuccess; - } - - /** - * the operation is finished after we receive the http stream - */ - public void replyHandler(InputStream response, CommRecord cr) { - mSuccess = false; - - try { - BufferedReader rspStream = - new BufferedReader(new InputStreamReader(response, "UTF8")); - String rspStr; - - Debug.println("CMSRequestCert: replyHandler() - start"); - mErrorMsg = mResource.getString("REQUESTRESULTWIZARD_TEXT_ERRORDESC_LABEL"); - while ((rspStr = rspStream.readLine()) != null && !mSuccess) - { - Debug.println("RequestCert: replyHandler() - read [" + rspStr + "]"); - // NMC_ messages are parsed, but not shown to the user - parse2(rspStr); - } - mErrorMsg = mErrorMsg + - mResource.getString("REQUESTRESULTWIZARD_TEXT_ERROREND_LABEL"); - String requestStatus =mWizardInfo.getRequestStatus(); - if ((mWizardInfo.getRequestError() != null) && - mWizardInfo.getRequestError().equals("true")) { - mWizardInfo.setRequestError(mErrorMsg); - mErrorMsg = null; - mSuccess = true; - } else if (requestStatus == null) { - // agent port, Unauthorizied access - mErrorMsg = mResource.getString("CGITASK_DIALOG_WRONGSERVER_MESSAGE"); - } else if (requestStatus.equals("5")) { - // rejected - if (mPolicyMsg == null) { - mWizardInfo.setRequestError(mResource.getString("REQUESTRESULTWIZARD_TEXT_NODETAIL_LABEL")); - } else { - mWizardInfo.setRequestError(mPolicyMsg); - mPolicyMsg = null; - } - mSuccess = true; - } - // Use the same format for other status:success,pending,svcPending - } catch (Exception e) { - Debug.println("RequestCert.Exception : " + e.toString()); - } - - Debug.println("RequestCert.replyHandler: finished, mSuccess=" + - mSuccess); - - finish(); - } - - - private void parse2(String s) - { - int iIndex; - Debug.println("Parse2 input: " + s); - if ((iIndex=s.indexOf("errorCode")) != (-1)) - { - String errorCode = s.substring(s.indexOf("\"") + 1, - s.lastIndexOf("\"")); - Debug.println("errorCode: " + errorCode); - if (errorCode.equals("2")) { // pending - mWizardInfo.setRequestError("false"); - mSuccess = true; - mWizardInfo.setRequestStatus("0"); - } else if (errorCode.equals("1")) { // error - mWizardInfo.setRequestError("true"); - mWizardInfo.setRequestStatus("5"); - mSuccess = false; - } else { - mWizardInfo.setRequestError("true"); - mWizardInfo.setRequestStatus("0"); - mSuccess = false; - } - } - else if ((iIndex=s.indexOf("requestList.requestId")) != (-1)) - { - String requestId = s.substring(s.indexOf("\"") + 1, - s.lastIndexOf("\"")); - Debug.println("requestId: " + requestId); - mWizardInfo.setRequestID(requestId); - } - else if ((iIndex=s.indexOf("errorReason")) != (-1)) - { - String errorReason = s.substring(s.indexOf("\"") + 1, - s.lastIndexOf("\"")); - Debug.println("errorReason: " + errorReason); - mErrorMsg = mErrorMsg + "\n " + errorReason; - } - } - - - - /** - * return the value for the given keyword in the reply - */ - private void parse(String s) { - String sName; - String sValue = null; - int iIndex; - - Debug.println("Parse input: " + s); - - if ((iIndex=s.indexOf("requestStatus = ")) != (-1)) - { - sName = s.substring(iIndex + 17).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mWizardInfo.setRequestStatus(sValue); - if (sValue.equals("2") || sValue.equals("3") - || sValue.equals("4")){ - //mSuccess = true; - } - } - } - else if ((iIndex=s.indexOf("requestId = ")) != (-1)) - { - sName = s.substring(iIndex + 13).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mWizardInfo.setRequestID(sValue); - //mSuccess = true; - } - } - else if ((iIndex=s.indexOf("unexpectedError = ")) != (-1)) - { - sName = s.substring(iIndex + 19).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - mWizardInfo.setRequestError("true"); - } - } - else if ((iIndex=s.indexOf("errorDetails = ")) != (-1)) - { - sName = s.substring(iIndex + 16).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - mWizardInfo.setRequestError("true"); - } - } - else if ((iIndex=s.indexOf("result.recordSet.length = ")) != (-1)) - { - sName = s.substring(iIndex + 27).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("") && !sValue.equals("0")) { - mErrorMsg = mErrorMsg + mResource.getString("REQUESTRESULTWIZARD_TEXT_DETAIL_LABEL");; - } - } - else if ((iIndex=s.indexOf("errorDescription = ")) != (-1)) - { - sName = s.substring(iIndex + 20).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - mErrorMsg = mErrorMsg + "\n " + sValue; - } - } - else if ((iIndex=s.indexOf("record.policyMessage=")) != (-1)) - { - sName = s.substring(iIndex + 22).trim(); - if ((iIndex = sName.indexOf("\"")) != (-1)) - sValue = sName.substring(0,iIndex); - - Debug.println("Parse input: name=" + sName + " output=" - + sValue + " index=" + iIndex); - if (sValue != null && !sValue.equals("")) { - if (mPolicyMsg == null) - mPolicyMsg = " " + sValue; - else - mPolicyMsg = mPolicyMsg + "\n " + sValue; - } - } - else if ((iIndex=s.indexOf("/HTML")) != (-1)) - mSuccess = true; // no need to parse further - - Debug.println("Parse finished"); - } - - /** - * Send an http request to the server. Return true if we're sure it - * succeeded, otherwise false. - */ - boolean run(Hashtable args) { - - String fullCmd = mWizardInfo.getCMEEType() + "://" + - mWizardInfo.getCMHost() + ":" + - mWizardInfo.getCMEEPort() + "/ca/ee/ca/profileSubmit"; - - HttpManager h = new HttpManager(); - // tell the http manager to use UTF8 encoding - h.setSendUTF8(true); - - try { - mSuccess = false; - mFinished = false; - - ByteArrayInputStream data = null; - if (args != null && !args.isEmpty()) - data = encode(args); - Debug.println( "Posting " + fullCmd ); - // tell the http manager to notify us immediately of replies - // if we're using async mode - int flags = 0; - CommRecord postResult = null; - if (data == null) - postResult = h.post(new URL(fullCmd), this, null, null, 0, - flags); - else - postResult = h.post(new URL(fullCmd), this, null, data, data.available(), - flags); - - /* - AdmTask admTask = new AdmTask(new URL(fullCmd),null,null); - admTask.setArguments(args); - admTask.exec(h); - */ - - awaitSuccess(); - - Object postStatus = postResult.getStatus(); - //Debug.println("status: " + postStatus); - if (postStatus != null && - postStatus.toString().equals(CommRecord.ERROR)) { - // If it happens to be it's not CMS server who is listening - // e.g. the cms agent port or yahoo server - // you may get here - mErrorMsg = mResource.getString("CGITASK_DIALOG_WRONGSERVER_MESSAGE"); - } - - Debug.println( "Command executed: " + fullCmd ); - } catch (Exception e) { - // This is very fragile. We have to handle it case by case. - // Handled the ones that I know of properly, but there may - // be other cases that I don't know, display the exception - // detail. - String detail = e.toString(); - if (detail == null || detail.trim().equals("")) - detail = "No detail of the exception provided."; - if ( e instanceof java.net.ConnectException ) { - mErrorMsg = mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE"); - //CMSAdminUtil.showMessageDialog(mResource, - // PREFIX, "CMSDOWN", CMSAdminUtil.ERROR_MESSAGE); - } else if ( e instanceof java.net.NoRouteToHostException ) { - // java.net.NoRouteToHostException: Connection timed out - // It takes 3-4 mins to time out, looks like hang to impatient - // ones. https://www.netscape.com:443 - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -; - } else if ( e instanceof java.net.SocketException ) { - if (detail.indexOf("Socket write failed") > -1){ - // retry - run(args); - } else if ((detail.indexOf("Connection shutdown") > -1) || - (detail.indexOf("Connection timed out") > -1) ) { - // java.net.NoRouteToHostException: Connection timed out - // double insurance - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE"); - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE")+ " java.net.SocketException: " + detail; - } - - } else if ( e instanceof java.io.IOException ) { - if (e.toString().indexOf("Broken pipe") > -1){ - // broken pipe, retry - run(args); - } else if (detail.indexOf("Unknown public-key algorithm") -> -1) { - mErrorMsg = - mResource.getString("CGITASK_DIALOG_UNKNOWNALG_MESSAGE") -; - } else if (detail.indexOf("End of input") > -1) { - // http://www.netscape.com:80/enrollment - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -; - } else if (detail.indexOf("Certificate fingerprint =") > -1) { - // reject the cms certificate - mErrorMsg = - mResource.getString("CGITASK_DIALOG_REJECTCERT_MESSAGE"); - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE" -) + " java.io.IOException: " + detail; - } - } else { - // need to determine case by case - mErrorMsg = - mResource.getString("CGITASK_DIALOG_CMSDOWN_MESSAGE") -+ " Exception: " + detail; - } - Debug.println( "Command " + fullCmd + " failed: " + e ); - } - return mSuccess; - } - -} - - - diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRestart.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRestart.java deleted file mode 100644 index fa9d59ddd..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSRestart.java +++ /dev/null @@ -1,186 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.management.client.console.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.connection.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import netscape.ldap.*; - -/** - * Start the server - * - * @author Jack Pan-Chen - * @version $Revision$, $Date$ - */ -public class CMSRestart extends CGITask -{ - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "TASKRESTART"; - public static final String RESTART_TASK_CGI = "Tasks/Operation/restart"; - //public static final String START_TASK_CGI = "Tasks/Operation/start"; - //public static final String STOP_TASK_CGI = "Tasks/Operation/stop"; - private Hashtable mCgiResponse = null; - private String mCgiTask = null; - - /*========================================================== - * constructors - *==========================================================*/ - - public CMSRestart() { - super(); - setName(mResource.getString(PREFIX+"_RESTART_LABEL")); - setDescription(mResource.getString(PREFIX+"_RESTART_DESC")); - } - - public void initialize(ConsoleInfo info) { - Debug.println("CMSStart: initialize()"); - _consoleInfo = info; - } - - /*========================================================== - * public methods - *==========================================================*/ - public boolean run(IPage viewInstance) - { - Debug.println("CMSRestart: run()"); - boolean status = false; // return value - AuthDialog dialog = new AuthDialog(UtilConsoleGlobals.getActivatedFrame()); - // dialog.show(); - if (dialog.isCancel()) - return false; - - Hashtable configParams = new Hashtable(); - configParams.put("serverRoot",_consoleInfo.get("serverRoot")); - - String servid = (String)_consoleInfo.get("servid"); - int index = servid.indexOf("-"); - if (index != -1) { - servid = servid.substring(index+1); - } - configParams.put("instanceID", servid); - configParams.put("password",dialog.getPassword()); - //configParams.put("instanceID",dialog.getInstanceName()); - Debug.println("password "+dialog.getPassword()); - - // get the CMS instance host and port - servid = (String)_consoleInfo.get("servid"); - String configDN = _consoleInfo.getCurrentDN(); - - try { - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - if (ldc == null) { - ldc = new LDAPConnection(); - } - if (ldc.isConnected() == false) { - ldc.connect(_consoleInfo.getHost(), _consoleInfo.getPort(), - _consoleInfo.getAuthenticationDN(), - _consoleInfo.getAuthenticationPassword()); - } - LDAPEntry entry = ldc.read(configDN); - String cmsHost = LDAPUtil.flatting( - entry.getAttribute("serverHostName", - LDAPUtil.getLDAPAttributeLocale())); - String cmsPort = LDAPUtil.flatting( - entry.getAttribute("nsServerPort", - LDAPUtil.getLDAPAttributeLocale())); - - Debug.println("host:" + cmsHost+" port:"+cmsPort); - configParams.put("cmsHost", cmsHost); - configParams.put("cmsPort", cmsPort); - } - catch (LDAPException e) { - Debug.println( - "ERROR CMSStatus: LDAP read failed: " + - configDN); - } - _consoleInfo.put("arguments", configParams); - - if (_consoleInfo.get("AdminUsername") == null) - _consoleInfo.put("AdminUsername", _consoleInfo.getAuthenticationDN() -); - Debug.println("AdminUsername = " + _consoleInfo.get("AdminUsername")); - - if (_consoleInfo.get("AdminUserPassword") == null) - _consoleInfo.put("AdminUserPassword", - _consoleInfo.getAuthenticationPassword()); - Debug.println("AdminUserPassword = " + _consoleInfo.get("AdminUserPassword")); - // call the CGI program - Debug.println("CMSRestart: restart() before run task="+RESTART_TASK_CGI); - try { - status = super.run(null, RESTART_TASK_CGI); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSRestart: start() after run status="+status); - - String title = mResource.getString("RESTARTRESULTDIALOG_TITLE"); - - if (!status) { - Debug.println("Show error dialog"); - // if no error message from the server, then just show the generic - // error message. - if (mErrorMsg.equals("")) - CMSAdminUtil.showMessageDialog( - UtilConsoleGlobals.getActivatedFrame(), - mResource, PREFIX, "SYSTEMERROR", CMSAdminUtil.ERROR_MESSAGE); - else { - String errorMsg = - mResource.getString("RESTARTRESULTDIALOG_FAILED_TEXT")+mErrorMsg; - Icon icon = CMSAdminUtil.getImage(CMSAdminResources.IMAGE_ERROR_ICON); - JOptionPane.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), - errorMsg, title, JOptionPane.ERROR_MESSAGE, icon); - } - } else { - CMSAdmin cmsAdmin = (CMSAdmin)(_consoleInfo.get("CMSAdmin")); - cmsAdmin.getServerStatus(); - Debug.println("Successful operation"); - String msg = ""; - // If warning message is received along with the started - // signal from the start.cc, we want to display the - // warning. - if (mWarnMsg.equals("")) { - msg = mResource.getString("RESTARTRESULTDIALOG_SUCCESS_TEXT"); - Icon icon = CMSAdminUtil.getImage(CMSAdminResources.IMAGE_INFO_ICON); - JOptionPane.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), - msg, title, JOptionPane.INFORMATION_MESSAGE, icon); - } else { - StringTokenizer st = new StringTokenizer(mWarnMsg, "|"); - while (st.hasMoreTokens()) { - msg += st.nextToken(); - if (st.hasMoreTokens()) { - msg += "\n"; - } - } - StatusDialog sd = new StatusDialog(UtilConsoleGlobals.getActivatedFrame()); - sd.showDialog(mResource.getString("RESTARTRESULTDIALOG_SUCCESS_TEXT"), msg); - } - } - - return status; - } -} - diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStart.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStart.java deleted file mode 100644 index 2122145c3..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStart.java +++ /dev/null @@ -1,179 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.management.client.console.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.connection.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import netscape.ldap.*; - -/** - * Start the server - * - * @author Jack Pan-Chen - * @version $Revision$, $Date$ - */ -public class CMSStart extends CGITask -{ - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "TASKSTART"; - public static final String START_TASK_CGI = "Tasks/Operation/start"; - private Hashtable mCgiResponse = null; - private String mCgiTask = null; - - /*========================================================== - * constructors - *==========================================================*/ - - public CMSStart() { - super(); - setName(mResource.getString(PREFIX+"_START_LABEL")); - setDescription(mResource.getString(PREFIX+"_START_DESC")); - } - - public void initialize(ConsoleInfo info) { - Debug.println("CMSStart: initialize()"); - _consoleInfo = info; - } - - /*========================================================== - * public methods - *==========================================================*/ - public boolean run(IPage viewInstance) - { - Debug.println("CMSStart: run()"); - boolean status = false; // return value - AuthDialog dialog = new AuthDialog(UtilConsoleGlobals.getActivatedFrame()); - // dialog.show(); - if (dialog.isCancel()) - return false; - - Hashtable configParams = new Hashtable(); - configParams.put("serverRoot",_consoleInfo.get("serverRoot")); - String servid = (String)_consoleInfo.get("servid"); - int index = servid.indexOf("-"); - if (index != -1) { - servid = servid.substring(index+1); - } - configParams.put("instanceID", servid); - configParams.put("password",dialog.getPassword()); - //configParams.put("instanceID",dialog.getInstanceName()); - Debug.println("password "+dialog.getPassword()); - - // get the CMS instance host and port - servid = (String)_consoleInfo.get("servid"); - String configDN = _consoleInfo.getCurrentDN(); - - try { - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - if (ldc == null) { - ldc = new LDAPConnection(); - } - if (ldc.isConnected() == false) { - ldc.connect(_consoleInfo.getHost(), _consoleInfo.getPort(), - _consoleInfo.getAuthenticationDN(), - _consoleInfo.getAuthenticationPassword()); - } - LDAPEntry entry = ldc.read(configDN); - String cmsHost = LDAPUtil.flatting( - entry.getAttribute("serverHostName", - LDAPUtil.getLDAPAttributeLocale())); - String cmsPort = LDAPUtil.flatting( - entry.getAttribute("nsServerPort", - LDAPUtil.getLDAPAttributeLocale())); - - Debug.println("host:" + cmsHost+" port:"+cmsPort); - configParams.put("cmsHost", cmsHost); - configParams.put("cmsPort", cmsPort); - } - catch (LDAPException e) { - Debug.println( - "ERROR CMSStatus: LDAP read failed: " + - configDN); - } - _consoleInfo.put("arguments", configParams); - - if (_consoleInfo.get("AdminUsername") == null) - _consoleInfo.put("AdminUsername", _consoleInfo.getAuthenticationDN() -); - Debug.println("AdminUsername = " + _consoleInfo.get("AdminUsername")); - - if (_consoleInfo.get("AdminUserPassword") == null) - _consoleInfo.put("AdminUserPassword", - _consoleInfo.getAuthenticationPassword()); - Debug.println("AdminUserPassword = " + _consoleInfo.get("AdminUserPassword")); - // call the CGI program - Debug.println("CMSStart: start() before run task="+START_TASK_CGI); - try { - status = super.run(null, START_TASK_CGI); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSStart: start() after run status="+status); - - String title = mResource.getString("STARTRESULTDIALOG_TITLE"); - - if (!status) { - Debug.println("Show error dialog"); - // if no error message from the server, then just show the generic - // error message. - if (mErrorMsg.equals("")) - CMSAdminUtil.showMessageDialog( - UtilConsoleGlobals.getActivatedFrame(), - mResource, PREFIX, "SYSTEMERROR", CMSAdminUtil.ERROR_MESSAGE); - else { - String errorMsg = - mResource.getString("STARTRESULTDIALOG_FAILED_TEXT")+mErrorMsg; - Icon icon = CMSAdminUtil.getImage(CMSAdminResources.IMAGE_ERROR_ICON); - JOptionPane.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), - errorMsg, title, JOptionPane.ERROR_MESSAGE, icon); - } - } else { - Debug.println("Successful operation"); - String msg = ""; - // If warning message is received along with the started - // signal from the start.cc, we want to display the - // warning. - if (mWarnMsg.equals("")) { - msg = mResource.getString("STARTRESULTDIALOG_SUCCESS_TEXT"); - Icon icon = CMSAdminUtil.getImage(CMSAdminResources.IMAGE_INFO_ICON); - JOptionPane.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), - msg, title, JOptionPane.INFORMATION_MESSAGE, icon); - } else { - StringTokenizer st = new StringTokenizer(mWarnMsg, "|"); - while (st.hasMoreTokens()) { - msg += st.nextToken(); - if (st.hasMoreTokens()) { - msg += "\n"; - } - } - StatusDialog sd = new StatusDialog(UtilConsoleGlobals.getActivatedFrame()); - sd.showDialog(mResource.getString("STARTRESULTDIALOG_SUCCESS_TEXT"), msg); - } - } - return status; - } -} diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStartDaemon.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStartDaemon.java deleted file mode 100644 index 510bf0661..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStartDaemon.java +++ /dev/null @@ -1,284 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.admin.certsrv.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import com.netscape.management.client.console.*; -import com.netscape.management.client.topology.*; -import com.netscape.management.client.comm.*; -import java.net.*; -import java.io.*; -import netscape.ldap.*; -import netscape.ldap.util.*; - -/** - * Start daemon to do the certificate server configuration. - * - * @author Christine Ho - * @version $Revision$, $Date$ - */ -public class CMSStartDaemon extends CGITask { - - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "CMSSTARTDAEMON"; - - public static final String START_DAEMON_CGI = "Tasks/Operation/start-daemon"; - - private boolean mSuccess = false; // status of last executed CGI - private Hashtable mCgiResponse = null; // holds parsed contents of CGI return - private String mCgiTask = null; // CGI task to call - - /*========================================================== - * constructors - *==========================================================*/ - public CMSStartDaemon() { - super(); - } - - /*========================================================== - * public methods - *==========================================================*/ - public void initialize(ConsoleInfo info) { - Debug.println("CMSStartDaemon: initialize()"); - _consoleInfo = info; - } - - /** - * Starts the server specific creation code, providing the DN for the - * target admin group. The method returns true or false depending - * on whether it was successful. - * - * @param targetDN - the admin group DN where the new instance is to be - * created. - * @return boolean value indicating whether the process succeeded (true) - * or failed (false). - */ - public boolean runDaemon(Hashtable configParams) { - String response = null; -/* - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - String ssdn = ldc.getAuthenticationDN(); - String[] avas = LDAPDN.explodeDN(ssdn, false); - String uid = avas[0]; - configParams.put("adminUID", uid.substring(4,uid.length())); - - configParams.put("adminPWD",ldc.getAuthenticationPassword()); - - _consoleInfo.put(START_DAEMON_CGI, "cert-bcsnpk"); -*/ - _consoleInfo.put("arguments", configParams); - - if (_consoleInfo.get("AdminUsername") == null) - _consoleInfo.put("AdminUsername", _consoleInfo.getAuthenticationDN()); - Debug.println("AdminUsername = " + _consoleInfo.get("AdminUsername")); - - if (_consoleInfo.get("AdminUserPassword") == null) - _consoleInfo.put("AdminUserPassword", - _consoleInfo.getAuthenticationPassword()); - Debug.println("AdminUserPassword = " + _consoleInfo.get("AdminUserPassword")); - - Debug.println("Current DN = "+_consoleInfo.getCurrentDN()); - boolean status = false; // return value - - try { - status = super.run(null, START_DAEMON_CGI); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSStartDaemon: startDaemon() after run status=" + - status + " mSuccess=" + mSuccess); -again: - if (!mSuccess) { - response = (String) mCgiResponse.get("NMC_ERRINFO"); - if ((response != null) && response.equalsIgnoreCase("daemon found lock file")) { - int result = CMSAdminUtil.showConfirmDialog(mResource, "CMSSTARTDAEMON"/*PREFIX*/, - "LOCKDELETECONFIRM", CMSAdminUtil.WARNING_MESSAGE); - if (result == CMSAdminUtil.OK_OPTION) { - Debug.println("User wants to delete lock file."); - configParams.put("IGNORE", "TRUE"); - status = super.run(null, START_DAEMON_CGI); - break again; - } - else - Debug.println("User doesn't want to delete lock file."); - } - else { - Debug.println("Show error dialog"); - CMSAdminUtil.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), mResource, PREFIX, - "SYSTEMERROR", CMSAdminUtil.ERROR_MESSAGE); - } - } - - return mSuccess; - } - - /** - * the operation is finished after we receive the http stream - */ - public void replyHandler(InputStream response, CommRecord cr) { - mSuccess = false; - if (mCgiResponse != null) - mCgiResponse.clear(); - - try { - BufferedReader rspStream = - new BufferedReader(new InputStreamReader(response, "UTF8")); - String rspStr; - - Debug.println("CMSStartDaemon: replyHandler() - start"); - while ((rspStr = rspStream.readLine()) != null) - { - Debug.println("CMSStartDaemon: replyHandler() - read [" + rspStr + "]"); - // NMC_ messages are parsed, but not shown to the user - /* - if (_statusText != null && !rspStr.startsWith("NMC_")) { - _statusText.append(rspStr + "\n"); - Thread.yield(); // allow graphics repaints - } - */ - parse(rspStr); - } - } catch (Exception e) { - Debug.println("StartDaemon.replyHandler: " + e.toString()); - } - - Debug.println("StartDaemon.replyHandler: finished, mSuccess=" + - mSuccess); - - finish(); - } - - /** - * return the value for the given keyword in the reply - */ - private void parse(String s) { - String sName; - String sValue; - int iIndex; - - Debug.println("Parse input: " + s); - - if ((iIndex=s.indexOf(":")) != (-1)) - { - sName = s.substring(0, iIndex).trim(); - sValue = s.substring(iIndex+1).trim(); - Debug.println("Parse input: name=" + sName + " value=" + sValue); - if (mCgiResponse == null) - mCgiResponse = new Hashtable(); - mCgiResponse.put(sName, sValue); - if (sName.equalsIgnoreCase("NMC_Status")) - { - int code = Integer.parseInt(sValue); - mSuccess = (code == 0); - Debug.println("Parse input: code=" + code + " mSuccess=" + mSuccess); - } - } - - Debug.println("Parse finished"); - } - - /** - * return the value for the response - */ - public Hashtable getResponse() { - return mCgiResponse; - } - - /** - * Get one value for one specified attribute from the given DN. - * If there is more than 1 entry which matches the given criteria, the - * first one will be used. - * - * @param DN DN of the entry with the specified attributes - * @param attr Attribute to get the value of - * @param scope LDAPConnection SCOPE_BASE SCOPE_ONE SCOPE_SUB - * @param filter LDAP search filter; if null, default is objectclass=* - * @return The string value of the attribute; multi-valued - * attributes are returned as 1 value, space delimited - * (flattened) - **/ - protected String getValue(String DN, String attr, int scope, - String filter) { - String[] attrs = { attr }; - String[] values = getValues(DN, attrs, scope, filter); - if (values != null) - return values[0]; - - return null; - } - - /** - * Get the values for several specified attributes from the given DN. - * If there is more than 1 entry which matches the given criteria, the - * first one will be used. - * - * @param DN DN of the entry with the specified attributes - * @param attrs Array of attributes to get the values of - * @param scope LDAPConnection SCOPE_BASE SCOPE_ONE SCOPE_SUB - * @param filter LDAP search filter; if null, default is objectclass=* - * @return An array of string values for each attribute; multi-valued - * attributes are returned as 1 value, space delimited - * (flattened) - **/ - protected String[] getValues(String DN, String[] attrs, int scope, - String filter) { - String[] values = null; - LDAPSearchResults results = null; - if (filter == null) - filter = "(objectclass=*)"; - - try { - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - if (ldc != null) - { - results = ldc.search(DN, scope, filter, attrs, false); - } - } catch (LDAPException e) { - Debug.println("error MigrateCreate.getValues: LDAP read failed " + - "for DN=" + DN + " attributes " + attrs); - Debug.println("error MigrateCreate.getValues: LDAP Exception:" + - e); - } - - if (results != null && results.hasMoreElements()) { - values = new String[attrs.length]; - LDAPEntry entry = (LDAPEntry)results.nextElement(); - for (int ii = 0; entry != null && ii < attrs.length; ++ii) { - values[ii] = LDAPUtil.flatting(entry.getAttribute(attrs[ii])); - } - } else { - Debug.println("error MigrateCreate.getValues: LDAP read failed " + - "for DN=" + DN + " attributes=" + attrs); - } - - return values; - } - -} diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStatus.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStatus.java deleted file mode 100644 index edd80b5b2..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStatus.java +++ /dev/null @@ -1,207 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import java.io.*; -import java.net.URL; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.management.client.console.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.connection.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import com.netscape.management.client.comm.*; -import netscape.ldap.*; - -/** - * Retrieve the status of the server - * - * @author Ross Fubini - * @version $Revision$, $Date$ - */ -public class CMSStatus extends CGITask -{ - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "TASKSTATUS"; - public static final String STATUS_TASK_CGI = "Tasks/Operation/status"; - private Hashtable mCgiResponse = null; - private String mCgiTask = null; - - /*========================================================== - * constructors - *==========================================================*/ - - public CMSStatus() { - super(); -/* - setName(mResource.getString(PREFIX+"_STATUS_LABEL")); - setDescription(mResource.getString(PREFIX+"_STATUS_DESC")); -*/ - } - - public void initialize(ConsoleInfo info) { - Debug.println("CMSStatus: initialize()"); - _consoleInfo = info; - } - - /*========================================================== - * public methods - *==========================================================*/ - public boolean run(IPage viewInstance) - { - Debug.println("CMSStatus: run()"); - boolean status = false; // return value - - Hashtable configParams = new Hashtable(); - configParams.put("serverRoot",_consoleInfo.get("serverRoot")); - String servid = (String)_consoleInfo.get("servid"); - int index = servid.indexOf("-"); - if (index != -1) { - servid = servid.substring(index+1); - } - configParams.put("instanceID", servid); - - // get the CMS instance host and port - servid = (String)_consoleInfo.get("servid"); - String configDN = _consoleInfo.getCurrentDN(); - - try { - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - if (ldc == null) { - ldc = new LDAPConnection(); - } - if (ldc.isConnected() == false) { - ldc.connect(_consoleInfo.getHost(), _consoleInfo.getPort(), - _consoleInfo.getAuthenticationDN(), - _consoleInfo.getAuthenticationPassword()); - } - LDAPEntry entry = ldc.read(configDN); - String cmsHost = LDAPUtil.flatting( - entry.getAttribute("serverHostName", - LDAPUtil.getLDAPAttributeLocale())); - String cmsPort = LDAPUtil.flatting( - entry.getAttribute("nsServerPort", - LDAPUtil.getLDAPAttributeLocale())); - - Debug.println("host:" + cmsHost+" port:"+cmsPort); - configParams.put("cmsHost", cmsHost); - configParams.put("cmsPort", cmsPort); - } - catch (LDAPException e) { - Debug.println( - "ERROR CMSStatus: LDAP read failed: " + - configDN); - } - _consoleInfo.put("arguments", configParams); - - if (_consoleInfo.get("AdminUsername") == null) - _consoleInfo.put("AdminUsername", _consoleInfo.getAuthenticationDN() -); - Debug.println("AdminUsername = " + _consoleInfo.get("AdminUsername")); - - if (_consoleInfo.get("AdminUserPassword") == null) - _consoleInfo.put("AdminUserPassword", - _consoleInfo.getAuthenticationPassword()); - Debug.println("AdminUserPassword = " + _consoleInfo.get("AdminUserPassword")); - - // call the CGI program - Debug.println("CMSStatus: status() before run task="+STATUS_TASK_CGI); - try { - status = getStatusWithFallback(null, STATUS_TASK_CGI); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSStatus: status() after run status="+status); - - if (!status) { - Debug.println("Status task returned false"); - } else { - Debug.println("Successful operation"); - } - return status; - } - - - /** - * Send an http request to the server. - * if the admin serever is down do - * Return true if we're sure it - * succeeded, otherwise false. - * - * @param viewInstance The calling page - * @param cmd Command to execute - */ - boolean getStatusWithFallback(IPage viewInstance, String cmd) { - // get the admin URL location first - mAdminURL = _consoleInfo.getAdminURL(); - if ( mAdminURL == null ) { - Debug.println( "Could not get adminURL for " + getDN() ); - return false; - } - - // Allow specifying e.g. "slapd-install" for instance - String instance = (String)_consoleInfo.get( cmd ); - - if ( instance == null ) - instance = (String)_consoleInfo.get( "ServerInstance" ); - String fullCmd = mAdminURL + instance + "/" + cmd; - - HttpManager h = new HttpManager(); - // tell the http manager to use UTF8 encoding - h.setSendUTF8(true); - - try { - mSuccess = false; - mFinished = false; - - // _consoleInfo.get("arguments") is a hashtable of key/value pairs - // to use as the arguments to the CGI - Hashtable args = (Hashtable)_consoleInfo.get("arguments"); - ByteArrayInputStream data = null; - if (args != null && !args.isEmpty()) - data = encode(args); - Debug.println( "Posting " + fullCmd ); - // tell the http manager to notify us immediately of replies - // if we're using async mode - int flags = 0; - if (data == null) - h.post(new URL(fullCmd), this, null, null, 0, - flags); - else - h.post(new URL(fullCmd), this, null, data, data.available(), - flags); - awaitSuccess(); - Debug.println( "Command executed: " + fullCmd ); - } catch (Exception e) { - if ( e instanceof java.net.ConnectException ) { - Debug.println( "Admin server failed to status task" ); - CMSAdmin cmsAdmin = (CMSAdmin)(_consoleInfo.get("CMSAdmin")); - mSuccess = cmsAdmin.getStatusFromAgentPort(); - } - Debug.println( "Falling back to get status by connecting to the server"); - - } - return mSuccess; - } -} - diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStop.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStop.java deleted file mode 100644 index b2a909633..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CMSStop.java +++ /dev/null @@ -1,161 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import javax.swing.*; -import com.netscape.management.client.*; -import com.netscape.management.client.console.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.connection.*; -import com.netscape.certsrv.common.*; -import com.netscape.management.client.util.*; -import netscape.ldap.*; - -/** - * Stop the server - * - * @author Christine Ho - * @version $Revision$, $Date$ - */ -public class CMSStop extends CGITask -{ - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "TASKSTOP"; - public static final String STOP_TASK_CGI = "Tasks/Operation/stop"; - private Hashtable mCgiResponse = null; - private String mCgiTask = null; - - /*========================================================== - * constructors - *==========================================================*/ - - public CMSStop() { - super(); - setName(mResource.getString(PREFIX+"_STOP_LABEL")); - setDescription(mResource.getString(PREFIX+"_STOP_DESC")); - } - - public void initialize(ConsoleInfo info) { - _consoleInfo = info; - } - - /*========================================================== - * public methods - *==========================================================*/ - public boolean run(IPage viewInstance) - { - Debug.println("CMSStop: run()"); - boolean status = false; // return value - /* - AuthDialog dialog = new AuthDialog(UtilConsoleGlobals.getActivatedFrame()); - dialog.show(); - if (dialog.isCancel()) - return false; - */ - Hashtable configParams = new Hashtable(); - configParams.put("serverRoot", _consoleInfo.get("serverRoot")); - String servid = (String)_consoleInfo.get("servid"); - int index = servid.indexOf("-"); - if (index != -1) { - servid = servid.substring(index+1); - } - configParams.put("instanceID", servid); - // configParams.put("password",dialog.getPassword()); - - // get the CMS instance host and port - servid = (String)_consoleInfo.get("servid"); - String configDN = _consoleInfo.getCurrentDN(); - - try { - LDAPConnection ldc = _consoleInfo.getLDAPConnection(); - if (ldc == null) { - ldc = new LDAPConnection(); - } - if (ldc.isConnected() == false) { - ldc.connect(_consoleInfo.getHost(), _consoleInfo.getPort(), - _consoleInfo.getAuthenticationDN(), - _consoleInfo.getAuthenticationPassword()); - } - LDAPEntry entry = ldc.read(configDN); - String cmsHost = LDAPUtil.flatting( - entry.getAttribute("serverHostName", - LDAPUtil.getLDAPAttributeLocale())); - String cmsPort = LDAPUtil.flatting( - entry.getAttribute("nsServerPort", - LDAPUtil.getLDAPAttributeLocale())); - - Debug.println("host:" + cmsHost+" port:"+cmsPort); - configParams.put("cmsHost", cmsHost); - configParams.put("cmsPort", cmsPort); - } - catch (LDAPException e) { - Debug.println( - "ERROR CMSStatus: LDAP read failed: " + - configDN); - } - _consoleInfo.put("arguments", configParams); - - if (_consoleInfo.get("AdminUsername") == null) - _consoleInfo.put("AdminUsername", _consoleInfo.getAuthenticationDN() -); - Debug.println("AdminUsername = " + _consoleInfo.get("AdminUsername")); - - if (_consoleInfo.get("AdminUserPassword") == null) - _consoleInfo.put("AdminUserPassword", - _consoleInfo.getAuthenticationPassword()); - Debug.println("AdminUserPassword = " + _consoleInfo.get("AdminUserPassword")); - // call the CGI program - Debug.println("CMSStop: stop() before run task="+STOP_TASK_CGI); - try { - status = super.run(null, STOP_TASK_CGI); - } catch (Exception e) { - Debug.println("Unexpected Error"+e.toString()); - status = false; - } - Debug.println("CMSStop: stop() after run status="+status); - - String title = mResource.getString("STOPRESULTDIALOG_TITLE"); - if (!status) { - Debug.println("Show error dialog"); - // if no error message from the server, then just show the generic - // error message. - if (mErrorMsg.equals("")) - CMSAdminUtil.showMessageDialog( - UtilConsoleGlobals.getActivatedFrame(), - mResource, PREFIX, "SYSTEMERROR", CMSAdminUtil.ERROR_MESSAGE); - else { - String errorMsg = - mResource.getString("STOPRESULTDIALOG_FAILED_TEXT")+mErrorMsg; - Icon icon = CMSAdminUtil.getImage(CMSAdminResources.IMAGE_ERROR_ICON); - JOptionPane.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), - errorMsg, title, JOptionPane.ERROR_MESSAGE, icon); - } - } else { - Debug.println("Successful operation"); - String msg = mResource.getString("STOPRESULTDIALOG_SUCCESS_TEXT"); - Icon icon = CMSAdminUtil.getImage(CMSAdminResources.IMAGE_INFO_ICON); - JOptionPane.showMessageDialog(UtilConsoleGlobals.getActivatedFrame(), - msg, title, JOptionPane.INFORMATION_MESSAGE, icon); - } - return status; - } -} - diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/CreateInstanceDialog.java b/pki/base/console/src/com/netscape/admin/certsrv/task/CreateInstanceDialog.java deleted file mode 100644 index 3092bf16d..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/CreateInstanceDialog.java +++ /dev/null @@ -1,246 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.awt.*; -import java.util.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.event.*; -import javax.swing.border.*; -import com.netscape.admin.certsrv.*; -import com.netscape.management.client.util.*; -import com.netscape.certsrv.common.*; - -/** - * Display this dialog to get the certificate - * instance name. - * - * @author Jack Pan-Chen - * @version $Revision$, $Date$ - */ -public class CreateInstanceDialog extends JDialog - implements ActionListener, DocumentListener, MouseListener -{ - /*========================================================== - * variables - *==========================================================*/ - private static final String PREFIX = "CREATEINSTANCE"; - - private static final int WIDTH = 300; - private static final int HEIGHT = 150; - private JTextField mInstanceField; // username textfield - private boolean mCanceled = true; // exit state of the dialog - private String mInstanceName; // username - private JFrame mParentFrame; - private ResourceBundle mResource; - private JButton mOK, mCancel; - private KeyListener mTextFieldKeyListener; - - /*========================================================== - * constructors - *==========================================================*/ - - /** - * @param parent parent frame - */ - public CreateInstanceDialog(JFrame parent) { - super(parent, true); - mParentFrame = parent; - mResource = - ResourceBundle.getBundle(CMSAdminResources.class.getName()); - mTextFieldKeyListener = new TextFieldKeyListener(); - setTitle(mResource.getString(PREFIX+"_TITLE")); - setLocationRelativeTo(parent); - - JPanel center = new JPanel(); - getContentPane().setLayout(new BorderLayout()); - GridBagLayout gb = new GridBagLayout(); - GridBagConstraints gbc = new GridBagConstraints(); - center.setLayout(gb); - - JPanel contentPanel = new JPanel(); - GridBagLayout gb1 = new GridBagLayout(); - contentPanel.setLayout(gb1); - - CMSAdminUtil.resetGBC(gbc); - gbc.anchor = gbc.NORTH; - gbc.gridwidth = gbc.REMAINDER; - gbc.weightx = 1.0; - gbc.weighty = 1.0; - gb.setConstraints(contentPanel, gbc); - center.add(contentPanel); - - CMSAdminUtil.resetGBC(gbc); - JLabel lUsername = - new JLabel(mResource.getString(PREFIX+"_LABEL_INSTANCE_LABEL")); - lUsername.setToolTipText( - mResource.getString(PREFIX+"_LABEL_INSTANCE_TTIP")); - - mInstanceField = new JTextField(); - mInstanceField.addKeyListener(mTextFieldKeyListener); - mInstanceField.getDocument().addDocumentListener(this); - mInstanceField.addMouseListener(this); - - CMSAdminUtil.addEntryField(contentPanel, lUsername, mInstanceField, - gbc); - - JPanel actionPanel = makeActionPane(); - - CMSAdminUtil.resetGBC(gbc); - gbc.anchor = gbc.NORTH; - gbc.gridwidth = gbc.REMAINDER; - gbc.gridheight = gbc.REMAINDER; - gbc.weightx = 1.0; - gb.setConstraints(actionPanel, gbc); - center.add(actionPanel); - - getContentPane().add("Center",center); - - mCanceled=false; - mInstanceName=""; - - setSize( WIDTH, HEIGHT ); - - addWindowListener( - new WindowAdapter() { - public void windowClosing(WindowEvent e) { - //setVisible(false); - dispose(); - mCanceled = true; - } - } - ); - - } - - /*========================================================== - * public methods - *==========================================================*/ - - /** - * return the exit status of the dialog - * - * @return true if the user hits the cancel button. - */ - public boolean isCancel() { - return mCanceled; - } - - /** - * Returns the username typed in by the user, on OK. - * - * @return The selected username, if the user hits the OK button. - */ - public String getInstanceName() { - return mInstanceName; - } - - /*========================================================== - * EVNET HANDLER METHODS - *==========================================================*/ - public void actionPerformed(ActionEvent evt) { - if (evt.getSource().equals(mOK)) { - mInstanceName = mInstanceField.getText().trim(); - - mCanceled = false; - //setVisible(false); - this.dispose(); - return; - - } - if (evt.getSource().equals(mCancel)) { - //setVisible(false); - mCanceled = true; - this.dispose(); - return; - } - } - - //== DocumentListener == - public void insertUpdate(DocumentEvent e) { - setButtons(); - } - - public void removeUpdate(DocumentEvent e){ - setButtons(); - } - - public void changedUpdate(DocumentEvent e){ - setButtons(); - } - - //==== MOUSELISTENER ====================== - public void mouseClicked(MouseEvent e) { - setButtons(); - } - - public void mousePressed(MouseEvent e) {} - public void mouseReleased(MouseEvent e) {} - public void mouseEntered(MouseEvent e) {} - public void mouseExited(MouseEvent e) { - setButtons(); - } - - /*========================================================== - * private methods - *==========================================================*/ - - private JPanel makeActionPane() { - mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, - this); - mOK.setEnabled(false); - mCancel = CMSAdminUtil.makeJButton(mResource, PREFIX, "CANCEL", - null, this); - - JButton[] buttons = { mOK, mCancel}; - JButtonFactory.resize( buttons ); - return CMSAdminUtil.makeJButtonPanel(buttons, false); - } - - //set buttons - private void setButtons() { - if (mInstanceField.getText().trim().equals("")){ - mOK.setEnabled(false); - } else { - mOK.setEnabled(true); - getRootPane().setDefaultButton(mOK); - } - } - - /** - * Inner class which handles key events for JTextField components. - */ - class TextFieldKeyListener implements KeyListener - { - public void keyTyped(KeyEvent e) { - } - - public void keyPressed(KeyEvent e) { - } - - public void keyReleased(KeyEvent e) { - if(e.getKeyCode() == KeyEvent.VK_ENTER) { - if (!mInstanceField.getText().trim().equals("")) { - mOK.doClick(); - } - } - } - } - -}
\ No newline at end of file diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/KeyCert.java b/pki/base/console/src/com/netscape/admin/certsrv/task/KeyCert.java deleted file mode 100644 index 589983f61..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/KeyCert.java +++ /dev/null @@ -1,62 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import java.util.*; -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.connection.*; -import com.netscape.management.client.*; -import com.netscape.management.client.console.*; -import com.netscape.admin.certsrv.keycert.*; - -/** - * Restart the server - * - * @author Jack Pan-Chen - * @version $Revision$, $Date$ - */ -public class KeyCert extends CMSTaskObject -{ - /*========================================================== - * variables - *==========================================================*/ - private static String PREFIX = "TASKKEYCERT_"; - - /*========================================================== - * constructors - *==========================================================*/ - - public KeyCert() { - setName(mResource.getString(PREFIX+"KEYCERT_LABEL")); - setDescription(mResource.getString(PREFIX+"KEYCERT_DESC")); - } - - /*========================================================== - * public methods - *==========================================================*/ - public boolean run(IPage viewInstance) { - ConsoleInfo console = getConsoleInfo(); - CMSServerInfo serverInfo = (CMSServerInfo)console.get("serverInfo"); - CMSBaseResourceModel model = new CMSBaseResourceModel(console, serverInfo); - AdminConnection admin = serverInfo.getAdmin(); - CertSetupWizardInfo wizardinfo = new CertSetupWizardInfo(admin, console); - CertSetupWizard wizard = new CertSetupWizard(model, wizardinfo); - return true; - } -} - diff --git a/pki/base/console/src/com/netscape/admin/certsrv/task/StatusDialog.java b/pki/base/console/src/com/netscape/admin/certsrv/task/StatusDialog.java deleted file mode 100644 index 0cd11beb5..000000000 --- a/pki/base/console/src/com/netscape/admin/certsrv/task/StatusDialog.java +++ /dev/null @@ -1,186 +0,0 @@ -// --- BEGIN COPYRIGHT BLOCK --- -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; version 2 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, write to the Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -// -// (C) 2007 Red Hat, Inc. -// All rights reserved. -// --- END COPYRIGHT BLOCK --- -package com.netscape.admin.certsrv.task; - -import com.netscape.admin.certsrv.*; -import com.netscape.admin.certsrv.connection.*; -import javax.swing.*; -import javax.swing.event.*; -import java.awt.event.*; -import java.awt.*; -import java.util.*; -import com.netscape.management.client.*; -import com.netscape.management.client.util.*; -import javax.swing.table.*; -import com.netscape.certsrv.common.*; - -/** - * Policy Implementation Information viewer - * - * @author Jack Pan-Chen - * @version $Revision$, $Date$ - * @see com.netscape.admin.certsrv.config - */ -public class StatusDialog extends JDialog - implements ActionListener -{ - /*========================================================== - * variables - *==========================================================*/ - private String PREFIX = "STATUSDIALOG"; - - private JFrame mParentFrame; - private ResourceBundle mResource; - private JTextArea mTextArea; - private JLabel mTitle, mDetails; - - private JButton mOK; - - /*========================================================== - * constructors - *==========================================================*/ - public StatusDialog(JFrame parent) { - super(parent,true); - mParentFrame = parent; - mResource = ResourceBundle.getBundle(CMSAdminResources.class.getName()); - setSize(300, 200); - setTitle(mResource.getString(PREFIX+"_TITLE")); - setLocationRelativeTo(parent); - getRootPane().setDoubleBuffered(true); - setDisplay(); - } - - /*========================================================== - * public methods - *==========================================================*/ - - /** - * show the windows - */ - public void showDialog(String title, String desc) { - //initialize and setup - mTitle.setText(title); - mDetails.setText("Details:"); - mTextArea.setText(desc); - mTextArea.setCaretPosition(0); - this.show(); - } - - /*========================================================== - * EVNET HANDLER METHODS - *==========================================================*/ - - //=== ACTIONLISTENER ===================== - public void actionPerformed(ActionEvent evt) { - if (evt.getSource().equals(mOK)) { - this.hide(); - } - } - - /*========================================================== - * private methods - *==========================================================*/ - private void setDisplay() { - getContentPane().setLayout(new BorderLayout()); - JPanel center = new JPanel(); - GridBagLayout gb = new GridBagLayout(); - GridBagConstraints gbc = new GridBagConstraints(); - center.setLayout(gb); - - //content panel - JPanel content = makeContentPane(); - CMSAdminUtil.resetGBC(gbc); - gbc.fill = gbc.BOTH; - gbc.anchor = gbc.NORTH; - gbc.gridwidth = gbc.REMAINDER; - gbc.weightx = 1.0; - gbc.weighty = 1.0; - gb.setConstraints(content, gbc); - center.add(content); - - //action panel - JPanel action = makeActionPane(); - CMSAdminUtil.resetGBC(gbc); - gbc.anchor = gbc.NORTH; - gbc.gridwidth = gbc.REMAINDER; - gbc.gridheight = gbc.REMAINDER; - gbc.weightx = 1.0; - gb.setConstraints(action, gbc); - center.add(action); - - getContentPane().add("Center",center); - } - - private JPanel makeActionPane() { - mOK = CMSAdminUtil.makeJButton(mResource, PREFIX, "OK", null, this); - Dimension d = mOK.getMinimumSize(); - if (d.width < CMSAdminUtil.DEFAULT_BUTTON_SIZE) { - d.width = CMSAdminUtil.DEFAULT_BUTTON_SIZE; - mOK.setMinimumSize(d); - } - JButton[] buttons = {mOK}; - return CMSAdminUtil.makeJButtonPanel( buttons ); - } - - private JPanel makeContentPane() { - JPanel content = new JPanel(); - GridBagLayout gb3 = new GridBagLayout(); - GridBagConstraints gbc = new GridBagConstraints(); - content.setLayout(gb3); - - mTitle = new JLabel(); - gbc.fill = gbc.HORIZONTAL; - gbc.gridwidth = gbc.REMAINDER; - gbc.weightx=1.0; - gbc.weighty=0.0; - gbc.insets = new Insets(CMSAdminUtil.COMPONENT_SPACE,CMSAdminUtil.COMPONENT_SPACE, CMSAdminUtil.COMPONENT_SPACE,CMSAdminUtil.COMPONENT_SPACE); - gb3.setConstraints(mTitle, gbc); - content.add(mTitle); - - mDetails = new JLabel(); - gbc.fill = gbc.HORIZONTAL; - gbc.gridwidth = gbc.REMAINDER; - gbc.weightx=1.0; - gbc.weighty=0.0; - gbc.insets = new Insets(CMSAdminUtil.COMPONENT_SPACE,CMSAdminUtil.COMPONENT_SPACE, CMSAdminUtil.COMPONENT_SPACE,CMSAdminUtil.COMPONENT_SPACE); - gb3.setConstraints(mDetails, gbc); - content.add(mDetails); - - CMSAdminUtil.resetGBC(gbc); - mTextArea = new JTextArea("",3,50); - mTextArea.setFont(mTitle.getFont()); - mTextArea.setEditable(false); - mTextArea.setBackground(getBackground()); - JScrollPane scrollPanel = new JScrollPane(mTextArea, - JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, - JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - scrollPanel.setAlignmentX(LEFT_ALIGNMENT); - scrollPanel.setAlignmentY(TOP_ALIGNMENT); - scrollPanel.setBackground(getBackground()); - //scrollPanel.setBorder(BorderFactory.createEmptyBorder()); - gbc.fill = gbc.BOTH; - gbc.gridwidth = gbc.REMAINDER; - gbc.gridheight = gbc.REMAINDER; - gbc.weightx=1.0; - gbc.weighty=1.0; - gb3.setConstraints(scrollPanel, gbc); - content.add(scrollPanel); - - return content; - } -} |