📄 installaction.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* 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; either version 2 of
* the License, or (at your option) any later version.
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.install.actions;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URLConnection;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.sslexplorer.boot.ContextHolder;
import com.sslexplorer.boot.KeyStoreManager;
import com.sslexplorer.boot.KeyStoreType;
import com.sslexplorer.boot.PropertyList;
import com.sslexplorer.boot.RepositoryFactory;
import com.sslexplorer.boot.RepositoryStore;
import com.sslexplorer.boot.Util;
import com.sslexplorer.core.CoreAttributeConstants;
import com.sslexplorer.core.CoreEvent;
import com.sslexplorer.core.CoreEventConstants;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.core.LicenseAgreement;
import com.sslexplorer.core.PropertyUtil;
import com.sslexplorer.core.UserDatabaseManager;
import com.sslexplorer.extensions.ExtensionBundle;
import com.sslexplorer.extensions.ExtensionBundleItem;
import com.sslexplorer.extensions.store.ExtensionStore;
import com.sslexplorer.extensions.store.ExtensionStoreDescriptor;
import com.sslexplorer.install.forms.ConfigureProxiesForm;
import com.sslexplorer.install.forms.ConfigureSuperUserForm;
import com.sslexplorer.install.forms.CreateNewCertificateForm;
import com.sslexplorer.install.forms.ImportExistingCertificateForm;
import com.sslexplorer.install.forms.InstallExtensionsForm;
import com.sslexplorer.install.forms.InstallForm;
import com.sslexplorer.install.forms.InstallXtraForm;
import com.sslexplorer.install.forms.SelectCertificateSourceForm;
import com.sslexplorer.install.forms.SelectUserDatabaseForm;
import com.sslexplorer.install.forms.SetKeyStorePasswordForm;
import com.sslexplorer.install.forms.WebServerForm;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.PublicKeyStore;
import com.sslexplorer.security.Role;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.User;
import com.sslexplorer.security.UserDatabase;
import com.sslexplorer.security.pki.SshPrivateKey;
import com.sslexplorer.setup.LicenseAgreementCallback;
import com.sslexplorer.wizard.AbstractWizardSequence;
import com.sslexplorer.wizard.WizardActionStatus;
import com.sslexplorer.wizard.actions.AbstractWizardAction;
public class InstallAction extends AbstractWizardAction {
public static final String SSLEXPLORER_SERVER = "sslexplorer-server";
final static Log log = LogFactory.getLog(InstallAction.class);
private String oldDatabase;
public InstallAction() {
super();
}
public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
return SessionInfo.SETUP_CONSOLE_CONTEXT;
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.wizard.actions.AbstractWizardAction#unspecified(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
// Do the install
List actionStatus = new ArrayList();
AbstractWizardSequence seq = getWizardSequence(request);
actionStatus.add(configureCertificate(seq));
actionStatus.add(configureUserDatabase(seq));
actionStatus.addAll(configureSuperUser(seq, request));
actionStatus.add(webServer(seq));
actionStatus.add(configureProxies(seq));
List extensionsToInstall = new ArrayList();
ExtensionStore store = ExtensionStore.getInstance();
if (seq.getAttribute(InstallXtraForm.ATTR_INSTALL_XTRA, "false").equals("true")) {
extensionsToInstall.add(InstallXtraForm.ENTERPRISE_CORE_BUNDLE_ID);
ExtensionStoreDescriptor descriptor = store.getDownloadableExtensionStoreDescriptor(true);
for (Iterator i = descriptor.getExtensionBundles().iterator(); i.hasNext();) {
ExtensionBundle bundle = (ExtensionBundle) i.next();
if(bundle.getId().startsWith("sslexplorer-enterprise")) {
if (!store.isExtensionLoaded(bundle.getId())) {
extensionsToInstall.add(bundle.getId());
}
}
}
}
for (Iterator i = seq.getAttributes().entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
if (entry.getKey().toString().startsWith(InstallExtensionsForm.ATTR_INSTALL_BUNDLE_PREFIX)
&& entry.getValue().equals("true")) {
extensionsToInstall.add(entry.getKey().toString().substring(
InstallExtensionsForm.ATTR_INSTALL_BUNDLE_PREFIX.length()));
}
}
boolean forwardToLicense = false;
ActionForward fwd = super.unspecified(mapping, form, request, response);
for (Iterator i = extensionsToInstall.iterator(); i.hasNext();) {
String ext = (String) i.next();
URLConnection con = ExtensionStore.getInstance().downloadExtension(ext);
try {
ExtensionBundle bundle = null;
if (ExtensionStore.getInstance().isExtensionBundleLoaded(ext)) {
bundle = ExtensionStore.getInstance().updateExtension(ext, con.getInputStream(), request);
} else {
bundle = ExtensionStore.getInstance().installExtension(ext, con.getInputStream(), request);
File licenseFile = bundle.getLicenseFile();
final RepositoryStore repStore = RepositoryFactory.getRepository().getStore(ExtensionStore.ARCHIVE_STORE);
if (licenseFile != null && licenseFile.exists()) {
forwardToLicense = true;
CoreUtil.requestLicenseAgreement(request.getSession(), new LicenseAgreement(bundle.getName(), licenseFile,
new ExtensionLicenseAgreementCallback(repStore, bundle, actionStatus), fwd));
}
else {
ExtensionStore.getInstance().postInstallExtension(bundle, request);
actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_OK,
"installation.install.status.installedExtension", bundle.getName(), bundle.getId()));
}
}
} catch (Exception e) {
log.error("Failed to install extension " + ext + ".", e);
actionStatus.add(new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.failedToInstallExtension", ext, e.getMessage()));
}
}
((InstallForm) form).setActionStatus(actionStatus);
if(forwardToLicense) {
return mapping.findForward("licenseAgreement");
}
return fwd;
}
public ActionForward redisplay(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("display");
}
public ActionForward exit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.getSession().removeAttribute(Constants.WIZARD_SEQUENCE);
return mapping.findForward("exit");
}
public ActionForward rerun(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("rerun");
}
protected AbstractWizardSequence createWizardSequence(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
throw new Exception("Cannot create sequence on this page.");
}
WizardActionStatus configureProxies(AbstractWizardSequence seq) {
try {
// boolean useSOCKSProxy = "true".equals(seq.getAttribute(ConfigureProxiesForm.ATTR_USE_SOCKS_PROXY, "false"));
boolean useHTTPProxy = "true".equals(seq.getAttribute(ConfigureProxiesForm.ATTR_USE_HTTP_PROXY, "false"));
/*
* Configure SOCKS proxy. Note Maverick HTTP does not yet support this
* but will at some point ;-)
*/
// if (useSOCKSProxy) {
// PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.socksProxyHost",
// (String) seq.getAttribute(ConfigureProxiesForm.ATTR_SOCKS_PROXY_HOSTNAME, ""), seq.getSession());
// PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.socksProxyPort",
// (String) seq.getAttribute(ConfigureProxiesForm.ATTR_SOCKS_PROXY_PORT, ""), getSessionInfo());
// PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.socksProxyUser",
// (String) seq.getAttribute(ConfigureProxiesForm.ATTR_SOCKS_PROXY_USERNAME, ""), getSessionInfo());
// PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.socksProxyPassword",
// (String) seq.getAttribute(ConfigureProxiesForm.ATTR_SOCKS_PROXY_PASSWORD, ""), getSessionInfo());
// } else {
// PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.socksProxyHost", "", getSessionInfo());
// PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.socksProxyPort", "3128", getSessionInfo());
// PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.socksProxyUser", "", getSessionInfo());
// PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.socksProxyPassword", "", getSessionInfo());
// }
/*
* Configure HTTP proxy. Supported by both Java API and Maverick HTTP.
*/
if (useHTTPProxy) {
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.proxyHost",
(String) seq.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_HOSTNAME, ""), getSessionInfo());
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.proxyPort",
(String) seq.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_PORT, ""), getSessionInfo());
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.proxyUser",
(String) seq.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_USERNAME, ""), getSessionInfo());
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.proxyPassword",
(String) seq.getAttribute(ConfigureProxiesForm.ATTR_HTTP_PROXY_PASSWORD, ""), getSessionInfo());
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.nonProxyHosts",
( (PropertyList) seq.getAttribute(ConfigureProxiesForm.ATTR_HTTP_NON_PROXY_HOSTS, null) ).getAsPropertyText(), getSessionInfo());
} else {
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.proxyHost", "", getSessionInfo());
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.proxyPort", "1080", getSessionInfo());
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.proxyUser", "", getSessionInfo());
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.proxyPassword", "", getSessionInfo());
PropertyUtil.getPropertyUtil().setProperty(0, null, "proxies.http.nonProxyHosts", "", getSessionInfo());
}
return new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.proxiesConfigured");
} catch (Exception e) {
log.error("Failed to configure web server.", e);
return new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.failedToConfigureProxies", e.getMessage());
}
}
WizardActionStatus configureUserDatabase(AbstractWizardSequence seq) {
try {
oldDatabase = PropertyUtil.getPropertyUtil().setProperty(0, null, "security.userDatabase",
(String) seq.getAttribute(SelectUserDatabaseForm.ATTR_USER_DATABASE, "builtIn"), seq.getSession());
return new WizardActionStatus(WizardActionStatus.COMPLETED_OK, "installation.install.status.userDatabaseConfigured");
} catch (Exception e) {
log.error("Failed to configure user database.", e);
return new WizardActionStatus(WizardActionStatus.COMPLETED_WITH_ERRORS,
"installation.install.status.failedToConfigureUserDatabase", e.getMessage());
}
}
WizardActionStatus webServer(AbstractWizardSequence seq) {
try {
PropertyUtil.getPropertyUtil().setProperty(0, null, "webServer.port",
(String) seq.getAttribute(WebServerForm.ATTR_WEB_SERVER_PORT, "443"), seq.getSession());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -