using System; using System.Data; using System.Net.Mail; using System.Net.Mime; using System.Text; using System.Threading; using CMS.CMSHelper; using CMS.EmailEngine; using CMS.GlobalHelper; using CMS.IO; using CMS.LicenseProvider; using CMS.SettingsProvider; using CMS.SiteProvider; using CMS.DocumentEngine; using CMS.UIControls; public partial class CMSModules_Support_Pages_SubmitIssue : SiteManagerPage { #region "Methods" protected void Page_Load(object sender, EventArgs e) { // Setup page title text and image CurrentMaster.Title.TitleText = GetString("SubmitIssue.Title"); CurrentMaster.Title.TitleImage = GetImageUrl("CMSModules/CMS_Support/SubmitIssueLarge.png"); CurrentMaster.Title.HelpTopicName = "submit_issue"; CurrentMaster.Title.HelpName = "helpTopic"; rfvEmail.Text = GetString("Support.SubmiIssue.EmailEmpty"); rfvSubject.Text = GetString("Support.SubmiIssue.SubjectEmpty"); htmlTemplateBody.DefaultLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; htmlTemplateBody.EditorAreaCSS = string.Empty; if (!RequestHelper.IsPostBack()) { // Initialize system info txtSysInfo.Text = GetSystemInformation(); ShowInformation(GetString("support.checksmtp")); } } /// /// Send e-mail to support. /// protected void btnSend_Click(object sender, EventArgs e) { string result = new Validator() .NotEmpty(txtSubject.Text.Trim(), GetString("Support.SubmiIssue.SubjectEmpty")) .NotEmpty(txtEmail.Text.Trim(), GetString("Support.SubmiIssue.EmailEmpty")) .IsEmail(txtEmail.Text.Trim(), GetString("Support.SubmiIssue.EmailFormat")) .Result; if (!string.IsNullOrEmpty(result)) { ShowError(result); return; } EmailMessage message = new EmailMessage { EmailFormat = EmailFormatEnum.Html, From = txtEmail.Text.Trim(), Subject = txtSubject.Text.Trim(), Recipients = "support@kentico.com" }; StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(htmlTemplateBody.ResolvedValue); sb.Append("
=============== System information ==================
"); sb.Append(txtSysInfo.Text.Replace("\r", string.Empty).Replace("\n", "
")); sb.Append("
==============================================

"); sb.Append("
================ Template type ==================
"); sb.Append(GetEngineInfo()); sb.Append("
"); sb.Append("=============================================
"); sb.Append(""); message.Body = sb.ToString(); // Add settings attachment if (chkSettings.Checked) { // Get settings data string settings = GetSettingsInfo(); if (!string.IsNullOrEmpty(settings)) { Stream stream = MemoryStream.New(); // Put the file content in the stream StreamWriter writer = StreamWriter.New(stream, UnicodeEncoding.UTF8); writer.Write(settings); writer.Flush(); stream.Seek(0, SeekOrigin.Begin); message.Attachments.Add(new Attachment(stream.SystemStream, "settings.txt", MediaTypeNames.Application.Octet)); } } // Add uploaded attachment if (fileUpload.HasFile) { Attachment at = new Attachment(fileUpload.PostedFile.InputStream, fileUpload.FileName, MediaTypeNames.Application.Octet); if (at != null) { message.Attachments.Add(at); } } EmailSender.SendEmail(null, message, true); ShowInformation(GetString("Support.Success")); ClearForm(); } /// /// Clears the form. /// protected void ClearForm() { txtEmail.Text = string.Empty; txtSubject.Text = string.Empty; txtSysInfo.Text = GetSystemInformation(); htmlTemplateBody.ResolvedValue = string.Empty; chkSettings.Checked = true; radDontKnow.Checked = true; radAspx.Checked = radMix.Checked = radPortal.Checked = false; } /// /// Gets data from the global and current site Settings. /// private static string GetSettingsInfo() { StringBuilder sb = new StringBuilder(); sb.Append("----------Settings---------"); sb.AppendLine(); sb.AppendLine(); // Get global settings data sb.Append(GetSettingsString(0, null)); int siteId = CMSContext.CurrentSiteID; if (siteId > 0) { // Get current site settings data sb.Append(GetSettingsString(siteId, CMSContext.CurrentSiteName)); } return sb.ToString(); } /// /// Returns string with Settings information for specified site. /// /// Site ID or 0 for global Settings /// Site name or null for global Settings private static string GetSettingsString(int siteId, string siteName) { DataSet setsDs; // Get global setting categories if (siteId == 0) { setsDs = SettingsCategoryInfoProvider.GetSettingsCategories(null, "CategoryName,CategoryOrder"); } // Get site setting categories else { setsDs = SettingsCategoryInfoProvider.GetSettingsCategories("CategoryID IN (SELECT KeyCategoryID FROM CMS_SettingsKey WHERE SiteID = " + siteId + ")", "CategoryName,CategoryOrder"); } // Check if any result exists if (DataHelper.DataSourceIsEmpty(setsDs)) { return string.Empty; } StringBuilder sb = new StringBuilder(); DataSet keyDs = null; string site = siteId > 0 ? siteName : "GLOBAL SETTINGS"; sb.Append(" - "); sb.Append(site); sb.AppendLine(); // Loop through all setting categories string prefix; foreach (DataRow setsDr in setsDs.Tables[0].Rows) { // Get settings keys for specific category keyDs = SettingsKeyProvider.GetSettingsKeys(siteId, ValidationHelper.GetInteger(setsDr["CategoryId"], 0)); if (!DataHelper.DataSourceIsEmpty(keyDs)) { // Display only not empty categories sb.Append("\r\n\t - "); sb.Append(ResHelper.LocalizeString(ValidationHelper.GetString(setsDr["CategoryName"], string.Empty))); sb.AppendLine(); prefix = "\t\t - "; // Display keys for category foreach (DataRow keyDr in keyDs.Tables[0].Rows) { if (keyDr["KeyValue"] != DBNull.Value) { sb.AppendFormat("{0}{1} '{2}' ({3})", prefix, ValidationHelper.GetString(keyDr["KeyName"], string.Empty), ValidationHelper.GetString(keyDr["KeyValue"], string.Empty), ValidationHelper.GetString(keyDr["KeyType"], string.Empty)); sb.AppendLine(); } } } } sb.AppendLine(); return sb.ToString(); } /// /// Returns system information. /// private static string GetSystemInformation() { StringBuilder sb = new StringBuilder(); sb.AppendFormat("CMS version: {0} Build: {1}", CMSContext.SYSTEM_VERSION, typeof(TreeProvider).Assembly.GetName().Version.ToString(3)); sb.AppendLine(); sb.AppendFormat("OS version: {0}", Environment.OSVersion); sb.AppendLine(); LicenseKeyInfo licenseKey = null; if (CMSContext.CurrentSite != null) { licenseKey = LicenseKeyInfoProvider.GetLicenseKeyInfo(CMSContext.CurrentSite.DomainName); } if (licenseKey != null) { sb.AppendFormat("License info: {0}, {1}, {2}, {3}", licenseKey.Domain, licenseKey.Edition, licenseKey.ExpirationDateReal.ToString(DateTimeHelper.DefaultIFormatProvider), licenseKey.Version); string packages = ValidationHelper.GetString(licenseKey.GetValue("LicensePackages"), string.Empty); if (!string.IsNullOrEmpty(packages)) { sb.AppendFormat(", {0}", packages); } } return sb.ToString(); } private string GetEngineInfo() { if (radAspx.Checked) { return "ASPX Templates"; } if (radPortal.Checked) { return "Portal engine"; } if (radMix.Checked) { return "Both"; } if (radDontKnow.Checked) { return "I don't know"; } return string.Empty; } #endregion }