com.aoindustries.website.signup.ServerConfirmationCompletedActionHelper Maven / Gradle / Ivy
/*
* aoweb-struts-core - Core API for legacy Struts-based site framework with AOServ Platform control panels.
* Copyright (C) 2007-2009, 2015, 2016, 2017, 2018, 2019 AO Industries, Inc.
* [email protected]
* 7262 Bull Pen Cir
* Mobile, AL 36695
*
* This file is part of aoweb-struts-core.
*
* aoweb-struts-core 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 3 of the License, or
* (at your option) any later version.
*
* aoweb-struts-core 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with aoweb-struts-core. If not, see .
*/
package com.aoindustries.website.signup;
import com.aoindustries.aoserv.client.AOServConnector;
import com.aoindustries.aoserv.client.billing.PackageDefinition;
import com.aoindustries.aoserv.client.linux.User;
import com.aoindustries.aoserv.client.payment.CountryCode;
import com.aoindustries.aoserv.client.reseller.Brand;
import com.aoindustries.encoding.ChainWriter;
import com.aoindustries.net.Email;
import com.aoindustries.net.HostAddress;
import com.aoindustries.net.InetAddress;
import com.aoindustries.util.i18n.ThreadLocale;
import com.aoindustries.validation.ValidationException;
import com.aoindustries.website.Mailer;
import com.aoindustries.website.SiteSettings;
import com.aoindustries.website.Skin;
import static com.aoindustries.website.signup.ApplicationResources.accessor;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.sql.SQLException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.GenericValidator;
import org.apache.struts.action.ActionServlet;
/**
* Managed6CompletedAction and Dedicated6CompletedAction both use this to setup the request attributes. This is implemented
* here because inheritance is not possible and neither one is logically above the other.
*
* @author AO Industries, Inc.
*/
final public class ServerConfirmationCompletedActionHelper {
/**
* Make no instances.
*/
private ServerConfirmationCompletedActionHelper() {}
public static void addOptions(Map options, SignupCustomizeServerForm signupCustomizeServerForm) {
// Power option
options.put("powerOption", Integer.toString(signupCustomizeServerForm.getPowerOption()));
// CPU option
options.put("cpuOption", Integer.toString(signupCustomizeServerForm.getCpuOption()));
// RAM option
options.put("ramOption", Integer.toString(signupCustomizeServerForm.getRamOption()));
// SATA Controller option
options.put("sataControllerOption", Integer.toString(signupCustomizeServerForm.getSataControllerOption()));
// SCSI Controller option
options.put("scsiControllerOption", Integer.toString(signupCustomizeServerForm.getScsiControllerOption()));
// Disk options
int number = 0;
for(String diskOption : signupCustomizeServerForm.getDiskOptions()) {
if(diskOption!=null && diskOption.length()>0 && !diskOption.equals("-1")) {
options.put("diskOptions["+(number++)+"]", diskOption);
}
}
}
public static void addOptions(Map options, SignupCustomizeManagementForm signupCustomizeManagementForm) {
options.put("backupOnsiteOption", Integer.toString(signupCustomizeManagementForm.getBackupOnsiteOption()));
options.put("backupOffsiteOption", Integer.toString(signupCustomizeManagementForm.getBackupOffsiteOption()));
options.put("backupDvdOption", signupCustomizeManagementForm.getBackupDvdOption());
options.put("distributionScanOption", Integer.toString(signupCustomizeManagementForm.getDistributionScanOption()));
options.put("failoverOption", Integer.toString(signupCustomizeManagementForm.getFailoverOption()));
}
/**
* Stores to the database, if possible. Sets request attributes "pkey" and "statusKey", both as String type.
*/
public static void storeToDatabase(
ActionServlet servlet,
HttpServletRequest request,
AOServConnector rootConn,
PackageDefinition packageDefinition,
SignupBusinessForm signupBusinessForm,
SignupTechnicalForm signupTechnicalForm,
SignupBillingInformationForm signupBillingInformationForm,
Map options
) {
// Store to the database
int pkey;
String statusKey;
try {
CountryCode businessCountry = rootConn.getPayment().getCountryCode().get(signupBusinessForm.getBusinessCountry());
CountryCode baCountry = GenericValidator.isBlankOrNull(signupTechnicalForm.getBaCountry()) ? null : rootConn.getPayment().getCountryCode().get(signupTechnicalForm.getBaCountry());
pkey = rootConn.getSignup().getRequest().addSignupRequest(rootConn.getThisBusinessAdministrator().getUsername().getPackage().getBusiness().getBrand(),
InetAddress.valueOf(request.getRemoteAddr()),
packageDefinition,
signupBusinessForm.getBusinessName(),
signupBusinessForm.getBusinessPhone(),
signupBusinessForm.getBusinessFax(),
signupBusinessForm.getBusinessAddress1(),
signupBusinessForm.getBusinessAddress2(),
signupBusinessForm.getBusinessCity(),
signupBusinessForm.getBusinessState(),
businessCountry,
signupBusinessForm.getBusinessZip(),
signupTechnicalForm.getBaName(),
signupTechnicalForm.getBaTitle(),
signupTechnicalForm.getBaWorkPhone(),
signupTechnicalForm.getBaCellPhone(),
signupTechnicalForm.getBaHomePhone(),
signupTechnicalForm.getBaFax(),
Email.valueOf(signupTechnicalForm.getBaEmail()),
signupTechnicalForm.getBaAddress1(),
signupTechnicalForm.getBaAddress2(),
signupTechnicalForm.getBaCity(),
signupTechnicalForm.getBaState(),
baCountry,
signupTechnicalForm.getBaZip(),
User.Name.valueOf(signupTechnicalForm.getBaUsername()),
signupBillingInformationForm.getBillingContact(),
Email.valueOf(signupBillingInformationForm.getBillingEmail()),
signupBillingInformationForm.getBillingUseMonthly(),
signupBillingInformationForm.getBillingPayOneYear(),
signupTechnicalForm.getBaPassword(),
signupBillingInformationForm.getBillingCardholderName(),
signupBillingInformationForm.getBillingCardNumber(),
signupBillingInformationForm.getBillingExpirationMonth(),
signupBillingInformationForm.getBillingExpirationYear(),
signupBillingInformationForm.getBillingStreetAddress(),
signupBillingInformationForm.getBillingCity(),
signupBillingInformationForm.getBillingState(),
signupBillingInformationForm.getBillingZip(),
options
);
statusKey = "serverConfirmationCompleted.success";
} catch(RuntimeException | ValidationException | IOException | SQLException err) {
servlet.log("Unable to store signup", err);
pkey = -1;
statusKey = "serverConfirmationCompleted.error";
}
request.setAttribute("statusKey", statusKey);
request.setAttribute("pkey", Integer.toString(pkey));
}
public static void sendSupportSummaryEmail(
ActionServlet servlet,
HttpServletRequest request,
String pkey,
String statusKey,
SiteSettings siteSettings,
PackageDefinition packageDefinition,
SignupCustomizeServerForm signupCustomizeServerForm,
SignupCustomizeManagementForm signupCustomizeManagementForm,
SignupBusinessForm signupBusinessForm,
SignupTechnicalForm signupTechnicalForm,
SignupBillingInformationForm signupBillingInformationForm
) {
try {
sendSummaryEmail(servlet, request, pkey, statusKey, siteSettings.getBrand().getAowebStrutsSignupAdminAddress(), siteSettings, packageDefinition, signupCustomizeServerForm, signupCustomizeManagementForm, signupBusinessForm, signupTechnicalForm, signupBillingInformationForm);
} catch(Exception err) {
servlet.log("Unable to send sign up details to support admin address", err);
}
}
/**
* Sends the customer emails and stores the successAddresses and failureAddresses as request attributes.
*/
public static void sendCustomerSummaryEmails(
ActionServlet servlet,
HttpServletRequest request,
String pkey,
String statusKey,
SiteSettings siteSettings,
PackageDefinition packageDefinition,
SignupCustomizeServerForm signupCustomizeServerForm,
SignupCustomizeManagementForm signupCustomizeManagementForm,
SignupBusinessForm signupBusinessForm,
SignupTechnicalForm signupTechnicalForm,
SignupBillingInformationForm signupBillingInformationForm
) {
Set addresses = new HashSet<>();
addresses.add(signupTechnicalForm.getBaEmail());
addresses.add(signupBillingInformationForm.getBillingEmail());
Set successAddresses = new HashSet<>();
Set failureAddresses = new HashSet<>();
Iterator I=addresses.iterator();
while(I.hasNext()) {
String address=I.next();
boolean success = sendSummaryEmail(servlet, request, pkey, statusKey, address, siteSettings, packageDefinition, signupCustomizeServerForm, signupCustomizeManagementForm, signupBusinessForm, signupTechnicalForm, signupBillingInformationForm);
if(success) successAddresses.add(address);
else failureAddresses.add(address);
}
// Store request attributes
request.setAttribute("successAddresses", successAddresses);
request.setAttribute("failureAddresses", failureAddresses);
}
/**
* Sends a summary email and returns true
if successful.
*/
private static boolean sendSummaryEmail(
ActionServlet servlet,
HttpServletRequest request,
String pkey,
String statusKey,
String recipient,
SiteSettings siteSettings,
PackageDefinition packageDefinition,
SignupCustomizeServerForm signupCustomizeServerForm,
SignupCustomizeManagementForm signupCustomizeManagementForm,
SignupBusinessForm signupBusinessForm,
SignupTechnicalForm signupTechnicalForm,
SignupBillingInformationForm signupBillingInformationForm
) {
try {
Locale userLocale = ThreadLocale.get();
// Find the locale and related resource bundles
String charset = Skin.getCharacterSet(userLocale);
// Generate the email contents
CharArrayWriter cout = new CharArrayWriter();
ChainWriter emailOut = new ChainWriter(cout);
String htmlLang = getHtmlLang(userLocale);
emailOut.print("\n"
+ "\n"
+ "\n"
+ " \n");
// Embed the text-only style sheet
InputStream cssIn = servlet.getServletContext().getResourceAsStream("/textskin/global.css");
if(cssIn!=null) {
try {
emailOut.print(" \n");
} finally {
cssIn.close();
}
} else {
servlet.log("Warning: Unable to find resource: /global/textskin.css");
}
emailOut.print("\n"
+ "\n"
+ "\n"
+ " \n"
+ " ").print(accessor.getMessage(statusKey, pkey)).print("
\n"
+ "
\n"
+ " ").print(accessor.getMessage("serverConfirmationCompleted.belowIsSummary")).print("
\n"
+ "
\n"
+ " \n"
+ " ").print(accessor.getMessage("steps.selectServer.label")).print(" \n");
SignupSelectServerActionHelper.printConfirmation(emailOut, packageDefinition);
emailOut.print(" \n"
+ " ").print(accessor.getMessage("steps.customizeServer.label")).print(" \n");
AOServConnector rootConn = siteSettings.getRootAOServConnector();
SignupCustomizeServerActionHelper.printConfirmation(request, emailOut, rootConn, packageDefinition, signupCustomizeServerForm);
if(signupCustomizeManagementForm!=null) {
emailOut.print(" \n"
+ " ").print(accessor.getMessage("steps.customizeManagement.label")).print(" \n");
SignupCustomizeManagementActionHelper.printConfirmation(
request,
emailOut,
rootConn,
signupCustomizeManagementForm
);
}
emailOut.print(" \n"
+ " ").print(accessor.getMessage("steps.businessInfo.label")).print(" \n");
SignupBusinessActionHelper.printConfirmation(emailOut, rootConn, signupBusinessForm);
emailOut.print(" \n"
+ " ").print(accessor.getMessage("steps.technicalInfo.label")).print(" \n");
SignupTechnicalActionHelper.printConfirmation(emailOut, rootConn, signupTechnicalForm);
emailOut.print(" \n"
+ " ").print(accessor.getMessage("steps.billingInformation.label")).print(" \n");
SignupBillingInformationActionHelper.printConfirmation(emailOut, signupBillingInformationForm);
emailOut.print("
\n"
+ "\n"
+ "\n");
emailOut.flush();
// Send the email
Brand brand = siteSettings.getBrand();
Mailer.sendEmail(
HostAddress.valueOf(brand.getSignupEmailAddress().getDomain().getAOServer().getHostname()),
"text/html",
charset,
brand.getSignupEmailAddress().toString(),
brand.getSignupEmailDisplay(),
Collections.singletonList(recipient),
accessor.getMessage("serverConfirmationCompleted.email.subject", pkey),
cout.toString()
);
return true;
} catch(RuntimeException | IOException | SQLException | MessagingException err) {
servlet.log("Unable to send sign up details to "+recipient, err);
return false;
}
}
public static String getHtmlLang(Locale locale) {
String language = locale.getLanguage();
if(language!=null) {
String country = locale.getCountry();
if(country!=null) {
String variant = locale.getVariant();
if(variant!=null) return language+"-"+country+"-"+variant;
return language+"-"+country;
}
return language;
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy