summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/config/install/WIKRANumberPage.java
blob: 000b3eb9f3ebeaacd687b4e08b7a1d5ba59b3918 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// --- 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.config.install;

import java.awt.*;
import java.util.*;
import java.math.*;
import javax.swing.*;
import com.netscape.admin.certsrv.*;
import com.netscape.admin.certsrv.connection.*;
import com.netscape.admin.certsrv.wizard.*;
import com.netscape.certsrv.common.*;
import com.netscape.admin.certsrv.task.*;
import com.netscape.management.client.console.*;

/**
 * This panel asks for the starting serial number that the CA issues
 *
 * @author Michelle Zhao
 * @version $Revision$, $Date$
 * @see com.netscape.admin.certsrv.config.install
 */
class WIKRANumberPage extends WizardBasePanel implements IWizardPanel {
    private JTextArea mDesc;

    private String mSerialNumber;
    private JTextField mSerialNumberText;
    private JLabel mSerialNumberLabel;

    private String mEndSerialNumber = null;
    private JTextField mEndSerialNumberText;
    private JLabel mEndSerialNumberLabel;

    private String mbeginRequestNumber;
    private JTextField mbeginRequestNumberText;
    private JLabel mbeginRequestNumberLabel;
    
    private String mEndRequestNumber = null;
    private JTextField mEndRequestNumberText;
    private JLabel mEndRequestNumberLabel;
   
    private static final String DEFAULT_SERIAL_NUMBER = "1";
    private static final String PANELNAME = "KRAREQUESTNUMBERWIZARD";
    private static final String HELPINDEX =
      "install-ca-serialnumber-wizard-help";

    WIKRANumberPage(JDialog parent) {
        super(PANELNAME);
        mParent = parent;
        init();
    }

    WIKRANumberPage(JDialog parent, JFrame adminFrame) {
        super(PANELNAME);
        mParent = parent;
        mAdminFrame = adminFrame;
        init();
    }

    public boolean isLastPage() {
        return false;
    }

    public boolean initializePanel(WizardInfo info) {
		String serial;
        InstallWizardInfo wizardInfo = (InstallWizardInfo)info;
        setBorder(makeTitledBorder(PANELNAME));
        if (//wizardInfo.isKRACertLocalCA() || !wizardInfo.isInstallCertNow() ||
          !wizardInfo.isKRAInstalled() || wizardInfo.isKRACertInstalledDone()||
          wizardInfo.isNumberPageDone())
            return false;
        
		if (wizardInfo.isCloning())
			mDesc.setText(mResource.getString(PANELNAME+"_TEXT_HEADING_LABEL")
					 + mResource.getString(PANELNAME+"_TEXT_MORE_LABEL"));
		else 
			mDesc.setText(mResource.getString(PANELNAME+"_TEXT_HEADING_LABEL"));


        if ((serial = wizardInfo.getCASerialNumber()) != null)
        	mSerialNumberText.setText(serial);
		else
        	mSerialNumberText.setText(DEFAULT_SERIAL_NUMBER);

        if ((serial = wizardInfo.getRequestNumber()) != null)
        	mbeginRequestNumberText.setText(serial);
		else
        	mbeginRequestNumberText.setText(DEFAULT_SERIAL_NUMBER);

        if ((serial = wizardInfo.getCAEndSerialNumber()) != null)
        	mEndSerialNumberText.setText(serial);

        if ((serial = wizardInfo.getEndRequestNumber()) != null)
        	mEndRequestNumberText.setText(serial);
        return true; 
    }

    private String hexToDecimal(String hex, boolean isHex)
    {
        //String newHex = hex.substring(2);
        BigInteger bi;
        if(isHex)
         bi = new BigInteger(hex, 16);
        else
            bi = new BigInteger(hex, 10);
        return bi.toString();
    }

    private String DecToHex(String dec)
    {
        BigInteger bi;
         bi = new BigInteger(dec, 10);
        return bi.toString(16);
    }

    private boolean validateNumber(JTextField beginNumberField, JTextField endNumberField,String beginText, String endText,boolean isSerialNumber)
    {
        BigInteger num = null;
        BigInteger endNum = null;
        String serial = null;
        beginText = beginNumberField.getText().trim();
        if (beginText != null && !beginText.equals("")) {
            try {
                if (beginText.startsWith("0x")) {
                  serial = hexToDecimal(beginText.substring(2),true);
                } else {
                  serial = beginText;
                }
                num = new BigInteger(serial);
                if (num.compareTo(new BigInteger("0")) < 0) {
                    setErrorMessage("You must specify a positive value.");
                    return false;
                }
            } catch (NumberFormatException e) {
                setErrorMessage("You must specify a numeric value.");
                return false;
            }
            if(isSerialNumber)
              mSerialNumber = DecToHex(serial);
            else
              mbeginRequestNumber = serial;
        } else {
            if(isSerialNumber)
              mSerialNumber = "";
            else
              mbeginRequestNumber = "";
        }

        endText = endNumberField.getText().trim();
        if (endText != null && !endText.equals("")) {
            try {
                if (endText.startsWith("0x")) {
                  serial = hexToDecimal(endText.substring(2),true);
                } else {
                  serial = endText;
                }
                endNum = new BigInteger(serial);
                if (endNum.compareTo(new BigInteger("0")) < 0) {
                    setErrorMessage("You must specify a positive value.");
                    return false;
                }
            } catch (NumberFormatException e) {
                setErrorMessage("You must specify a numeric value.");
                return false;
            }
            if(isSerialNumber)
              mEndSerialNumber = DecToHex(serial);
            else
              mEndRequestNumber = serial;
        } else {
            if(isSerialNumber)
              mEndSerialNumber = "";
            else
              mEndRequestNumber = "";
        }
        
        if (num != null && endNum != null && num.compareTo(endNum) > 0) {
            setErrorMessage("Ending number must be greater than starting number.");
            return false;
        }
        return true;
    }

    public boolean validatePanel() {
       if(validateNumber(mSerialNumberText,mEndSerialNumberText,mSerialNumber,mEndSerialNumber,true)==false)
            return false;
       if(validateNumber(mbeginRequestNumberText,mEndRequestNumberText,mbeginRequestNumber,mEndRequestNumber,false)==false)
            return false;
        return true;
    }

    public boolean concludePanel(WizardInfo info) {
        InstallWizardInfo wizardInfo = (InstallWizardInfo)info;
		if (mSerialNumber != null && !mSerialNumber.equals("")) 
			wizardInfo.setCASerialNumber(mSerialNumber);
		else {
			wizardInfo.setCASerialNumber(DEFAULT_SERIAL_NUMBER);
			mSerialNumber = DEFAULT_SERIAL_NUMBER;
		}
		if (mbeginRequestNumber != null && !mbeginRequestNumber.equals("")) 
			wizardInfo.setRequestNumber(mbeginRequestNumber);
		else {
			wizardInfo.setRequestNumber(DEFAULT_SERIAL_NUMBER);
			mbeginRequestNumber = DEFAULT_SERIAL_NUMBER;
		}

        String rawData = ConfigConstants.TASKID+"="+TaskId.TASK_SET_KRA_NUMBER;
        rawData = rawData+"&"+ConfigConstants.OPTYPE+"="+OpDef.OP_MODIFY;
		if (mSerialNumber != null && !mSerialNumber.equals("")) 
            rawData = rawData+"&"+ConfigConstants.PR_CA_SERIAL_NUMBER+"="+
              mSerialNumber;
		if (mEndSerialNumber != null && !mEndSerialNumber.equals("")) 
            rawData = rawData+"&"+ConfigConstants.PR_CA_ENDSERIAL_NUMBER+"="+
              mEndSerialNumber;
		if (mbeginRequestNumber != null && !mbeginRequestNumber.equals("")) 
            rawData = rawData+"&"+ConfigConstants.PR_REQUEST_NUMBER+"="+
              mbeginRequestNumber;
		if (mEndRequestNumber != null && !mEndSerialNumber.equals("")) 
            rawData = rawData+"&"+ConfigConstants.PR_ENDREQUEST_NUMBER+"="+
              mEndRequestNumber;
        if (wizardInfo.getInternalDBPasswd() != null)
            rawData = rawData+"&"+ConfigConstants.PR_DB_PWD+"="+
              wizardInfo.getInternalDBPasswd();
        rawData = rawData+"&"+ConfigConstants.PR_SERIAL_REQUEST_NUMBER+"="+
          ConfigConstants.TRUE;

        startProgressStatus();

        boolean ready = send(rawData, wizardInfo);
        endProgressStatus();

        if (!ready) {
            String str = getErrorMessage();
            if (str.equals(""))
                setErrorMessage("Server Error");
            else
                setErrorMessage(str);
        }else {
            wizardInfo.setNumberPageDone(ConfigConstants.TRUE);
        }

        return ready;
    }

    public void callHelp() {
        CMSAdminUtil.help(HELPINDEX);
    }

    protected void init() {
        GridBagLayout gb = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        setLayout(gb);

        CMSAdminUtil.resetGBC(gbc);
        mDesc = createTextArea(mResource.getString(
            PANELNAME+"_TEXT_HEADING_LABEL"));
        gbc.anchor = gbc.NORTHWEST;
        gbc.weightx = 1.0;
        gbc.weighty = 0.0;
        gbc.insets = new Insets(COMPONENT_SPACE,COMPONENT_SPACE,
          COMPONENT_SPACE,COMPONENT_SPACE);
        gbc.gridwidth = gbc.REMAINDER;
        add(mDesc, gbc);

        CMSAdminUtil.resetGBC(gbc);
        mSerialNumberLabel = makeJLabel("SERIALNUMBER");
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(0, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mSerialNumberLabel, gbc);

        CMSAdminUtil.resetGBC(gbc);
        mSerialNumberText = makeJTextField(30);
        gbc.anchor = gbc.NORTHWEST;
//        gbc.fill = gbc.NONE;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.insets = new Insets(0, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mSerialNumberText, gbc);

        
        CMSAdminUtil.resetGBC(gbc);
        mEndSerialNumberLabel = makeJLabel("ENDSERIALNUMBER");
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mEndSerialNumberLabel, gbc);

        CMSAdminUtil.resetGBC(gbc);
        mEndSerialNumberText = makeJTextField(30);
        gbc.anchor = gbc.NORTHWEST;
//        gbc.fill = gbc.NONE;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mEndSerialNumberText, gbc);
        
        CMSAdminUtil.resetGBC(gbc);
        mbeginRequestNumberLabel = makeJLabel("REQUESTNUMBER");
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(0, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mbeginRequestNumberLabel, gbc);
        
        CMSAdminUtil.resetGBC(gbc);
        mbeginRequestNumberText = makeJTextField(30);
        gbc.anchor = gbc.NORTHWEST;
//        gbc.fill = gbc.NONE;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.insets = new Insets(0, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mbeginRequestNumberText, gbc);
        
        CMSAdminUtil.resetGBC(gbc);
        mEndRequestNumberLabel = makeJLabel("ENDREQUESTNUMBER");
        gbc.anchor = gbc.EAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mEndRequestNumberLabel, gbc);
        
        CMSAdminUtil.resetGBC(gbc);
        mEndRequestNumberText = makeJTextField(30);
        gbc.anchor = gbc.NORTHWEST;
//        gbc.fill = gbc.NONE;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.insets = new Insets(COMPONENT_SPACE, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mEndRequestNumberText, gbc);
        
        /*
        CMSAdminUtil.resetGBC(gbc);
        mSerialNumberLabel = makeJLabel("PWD");
        gbc.anchor = gbc.NORTHEAST;
        gbc.fill = gbc.NONE;
        gbc.insets = new Insets(0, 0, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mSerialNumberLabel, gbc);
        
        CMSAdminUtil.resetGBC(gbc);
        mSerialNumberText = makeJSerialNumberField(30);
        gbc.anchor = gbc.NORTHWEST;
        gbc.fill = gbc.NONE;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.insets = new Insets(0, COMPONENT_SPACE, COMPONENT_SPACE,
          COMPONENT_SPACE);
        add(mSerialNumberText, gbc);
*/
        JLabel dummy = new JLabel(" ");
        CMSAdminUtil.resetGBC(gbc);
        gbc.anchor = gbc.NORTHWEST;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.gridheight = gbc.REMAINDER;
        gbc.weighty = 1.0;
        add(dummy, gbc);
    }

    public void getUpdateInfo(WizardInfo info) {
    }
}