📄 install.java
字号:
/************************************************************************* * * * EJBCA: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package se.anatom.ejbca.admin;import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.Properties;import java.util.regex.Pattern;import org.ietf.ldap.LDAPDN;import se.anatom.ejbca.util.passgen.PasswordGeneratorFactory;/** Class used as an install script of ejbca * * @author philip * @version $Id: Install.java,v 1.14 2004/05/13 15:33:59 herrvendil Exp $ * * The main porpose of this program is to provide easy installment of EJBCA. */public class Install extends BaseCommand { public static int ARG_COMMAND = 0; public static int ARG_OS = 1; public static int ARG_LANGUAGE = 2; public static int ARG_VERSION = 3; public static int ARG_APPSERVER = 4; public static int ARG_WEBSERVER = 5; private final static int OS_UNIX = 0; private final static int OS_WINDOWS = 1; private final static int APPSERVER_JBOSS = 0; private final static int APPSERVER_WEBLOGIC = 1; private int appserver = APPSERVER_JBOSS; private int os = OS_UNIX; private String caname = ""; private String cadn = ""; private int keysize = 0; private int validity = 0; private String policyid = ""; private String computername = ""; private String servercertdn = ""; private String serverkeystorepasswd = ""; private String superadminpasswd = ""; private String javacacertspasswd = ""; private Pattern nondigit = Pattern.compile("\\D"); private Pattern nondigitordot = Pattern.compile("[^0-9\\.]"); private Pattern notcomputername = Pattern.compile("[^0-9a-zA-z\\-\\.]"); private Pattern nonword = Pattern.compile("\\W"); private Properties text; private BufferedReader reader = null; public Install(String osstring, String language, String version, String appserverstring) throws Exception{ super(); reader = new BufferedReader(new InputStreamReader(System.in)); text = new Properties(); text.load(this.getClass().getResourceAsStream("/" + "install." + language.toLowerCase() + ".properties")); if(osstring.equalsIgnoreCase("unix")){ this.os = OS_UNIX; } if(osstring.equalsIgnoreCase("windows")){ this.os = OS_WINDOWS; } if(appserverstring.equalsIgnoreCase("weblogic")){ this.appserver = APPSERVER_WEBLOGIC; } } public void run(){ if(checkRequirements()){; displayWelcomeScreen(); while(!collectData()); runInstall(); }else{ System.exit(-1); } } public static void main(String[] args) throws Exception { if(args.length != 5){ System.out.println("Usage: install install <unix|windows> <language> <ejbca|primeca> <jboss|weblogic>\n" + " Or : install displayendmessage <unix|windows> <language> <ejbca|primeca> <jboss|weblogic>"); System.exit(-1); } Install install = new Install(args[ARG_OS], args[ARG_LANGUAGE], args[ARG_VERSION], args[ARG_APPSERVER]); if(args.length == 5){ if(args[Install.ARG_COMMAND].equalsIgnoreCase("install")){ install.run(); }else{ if(args[Install.ARG_COMMAND].equalsIgnoreCase("displayendmessage")){ install.displayEndMessage(); }else{ System.out.println("Usage: install install <unix|windows> <language> <ejbca> <jboss|weblogic>\n" + " Or : install displayendmessage <unix|windows><language> <ejbca> <jboss|weblogic>"); System.exit(-1); } } } } /** * Method checking if all reuirements are meet before starting the installation. * If requirements aren't meet then will a error message be displayed. * * @return true if all requirements are set. */ private boolean checkRequirements(){ boolean appservrunning = appServerRunning(); boolean cryptoinstalled = false; if (!appservrunning) { System.out.println(text.getProperty("APPSERVMUSTBERUNNING")); } try { cryptoinstalled = strongCryptoInstalled(); } catch (Exception e) { System.out.println(text.getProperty("STRONGCRYPTOMUSTBEINSTALLED")); } return appservrunning && cryptoinstalled; } private void displayWelcomeScreen(){ System.out.print(text.getProperty("WELCOMETO")); System.out.print(text.getProperty("THISSCRIPT")); System.out.print(text.getProperty("THEAPPLICATIONISDEPLOYED")); System.out.print(text.getProperty("YOUSHOULDPERFORM")); System.out.print(text.getProperty("ISTHESEREQUIREMENTSMEET")); String answer = getAnswer(); while(!answerInBoolean(answer)){ System.out.print(text.getProperty("PLEASETYPEEITHERYESORNO")); answer = getAnswer(); } boolean cont = getBooleanAnswer(answer); if(!cont) System.exit(-1); } private boolean collectData(){ System.out.print(text.getProperty("THISINSTALLATIONWILL")); getCAName(); getCADN(); getKeySize(); getValidity(); getPolicyId(); System.out.print(text.getProperty("NOWSOMEADMINWEB")); getComputerName(); getSSLServerCertDN(); getSSLKeyStorePasswd(); getSuperAdminPasswd(); // getJavaCACertsPasswd(); return isDataCorrect(); } private void getCAName(){ System.out.print(text.getProperty("ENTERSHORTNAME")); String answer = getAnswer(); while(!answerLegalName(answer)){ System.out.print(text.getProperty("ILLEGALCANAME")); System.out.print(text.getProperty("ENTERSHORTNAME")); answer = getAnswer(); } this.caname = answer; } private void getCADN(){ System.out.print(text.getProperty("ENTERDN")); String answer = getAnswer(); while(!answerLegalDN(answer)){ System.out.print(text.getProperty("ILLEGALDN")); System.out.print(text.getProperty("ENTERDN")); answer = getAnswer(); } this.cadn = answer; } private void getKeySize(){ System.out.print(text.getProperty("ENTERKEYSIZE")); String answer = getAnswer(); while(!answerLegalKeySize(answer)){ System.out.print(text.getProperty("ILLEGALKEYSIZE")); System.out.print(text.getProperty("ENTERKEYSIZE")); answer = getAnswer(); } this.keysize = this.getDigitAnswer(answer); } private void getValidity(){ System.out.print(text.getProperty("ENTERVALIDITY")); String answer = getAnswer(); while(!answerLegalValidity(answer)){ System.out.print(text.getProperty("ILLEGALVALIDITY")); System.out.print(text.getProperty("ENTERVALIDITY")); answer = getAnswer(); } this.validity = this.getDigitAnswer(answer); } private void getPolicyId(){ System.out.print(text.getProperty("ENTERPOLICYID")); String answer = getAnswer(); while(!answerLegalPolicyId(answer)){ System.out.print(text.getProperty("ILLEGALPOLICYID")); System.out.print(text.getProperty("ENTERPOLICYID")); answer = getAnswer(); } this.policyid = this.getPolicyId(answer); } private void getComputerName(){ System.out.print(text.getProperty("ENTERCOMPUTERNAME")); String answer = getAnswer(); while(!answerLegalComputerName(answer)){ System.out.print(text.getProperty("ILLEGALCOMPUTERNAME")); System.out.print(text.getProperty("ENTERCOMPUTERNAME")); answer = getAnswer(); } this.computername = answer; } private void getSSLServerCertDN(){ System.out.print(text.getProperty("ENTERSERVERDN")); String answer = getAnswer(); while(!answerLegalDN(answer)){ System.out.print(text.getProperty("ILLEGALSERVERDN")); System.out.print(text.getProperty("ENTERSERVERDN")); answer = getAnswer(); } this.servercertdn = answer; } private void getSSLKeyStorePasswd(){ this.serverkeystorepasswd = PasswordGeneratorFactory.getInstance(PasswordGeneratorFactory.PASSWORDTYPE_LETTERSANDDIGITS).getNewPassword(8,8); /* System.out.print(text.getProperty("ENTERADMINWEBPASSWORD")); String answer = getAnswer(); while(!answerLegalPassword(answer)){ System.out.print(text.getProperty("ILLEGALADMINWEBPASSWORD")); System.out.print(text.getProperty("ENTERADMINWEBPASSWORD")); answer = getAnswer(); } this.serverkeystorepasswd = answer;*/ } private void getSuperAdminPasswd(){ System.out.print(text.getProperty("ENTERSUPERADMINPASSWORD")); String answer = getAnswer(); while(!answerLegalPassword(answer)){ System.out.print(text.getProperty("ILLEGALSUPERADMINPASSWORD")); System.out.print(text.getProperty("ENTERSUPERADMINPASSWORD"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -