PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Install/InstallWizard.aspx.cs

https://github.com/mailekah/AgapeConnect1
C# | 1973 lines | 1751 code | 66 blank | 156 comment | 79 complexity | fc9950f780b7efeb4eca08b6e1720603 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. #region Copyright
  2. //
  3. // DotNetNukeĊ½ - http://www.dotnetnuke.com
  4. // Copyright (c) 2002-2012
  5. // by DotNetNuke Corporation
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  8. // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  9. // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  10. // to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all copies or substantial portions
  13. // of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  16. // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  18. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  19. // DEALINGS IN THE SOFTWARE.
  20. #endregion
  21. #region Usings
  22. using System;
  23. using System.Collections;
  24. using System.Collections.Generic;
  25. using System.Data.Common;
  26. using System.Globalization;
  27. using System.IO;
  28. using System.Linq;
  29. using System.Net;
  30. using System.Net.Mail;
  31. using System.Text.RegularExpressions;
  32. using System.Threading;
  33. using System.Web;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. using System.Xml;
  37. using System.Xml.XPath;
  38. using ASP;
  39. using DotNetNuke.Application;
  40. using DotNetNuke.Common;
  41. using DotNetNuke.Common.Internal;
  42. using DotNetNuke.Common.Utilities;
  43. using DotNetNuke.Data;
  44. using DotNetNuke.Entities.Controllers;
  45. using DotNetNuke.Entities.Portals;
  46. using DotNetNuke.Entities.Portals.Internal;
  47. using DotNetNuke.Entities.Users;
  48. using DotNetNuke.Framework;
  49. using DotNetNuke.Instrumentation;
  50. using DotNetNuke.Security.Membership;
  51. using DotNetNuke.Services.Localization;
  52. using DotNetNuke.Services.Localization.Internal;
  53. using DotNetNuke.UI.Skins.Controls;
  54. using DotNetNuke.UI.Utilities;
  55. using DotNetNuke.Web.Client.ClientResourceManagement;
  56. using DataCache = DotNetNuke.Common.Utilities.DataCache;
  57. using Globals = DotNetNuke.Common.Globals;
  58. #endregion
  59. namespace DotNetNuke.Services.Install
  60. {
  61. /// -----------------------------------------------------------------------------
  62. /// <summary>
  63. /// The InstallWizard class provides the Installation Wizard for DotNetNuke
  64. /// </summary>
  65. /// <remarks>
  66. /// </remarks>
  67. /// <history>
  68. /// [cnurse] 01/23/2007 Created
  69. /// </history>
  70. /// -----------------------------------------------------------------------------
  71. public partial class InstallWizard : PageBase, IClientAPICallbackEventHandler
  72. {
  73. #region Private Members
  74. private readonly DataProvider _dataProvider = DataProvider.Instance();
  75. protected new string LocalResourceFile = "~/Install/App_LocalResources/InstallWizard.aspx.resx";
  76. private Version _dataBaseVersion;
  77. private XmlDocument _installTemplate;
  78. private const string LocalesFile = "/Install/App_LocalResources/Locales.xml";
  79. private string _connectionString = Null.NullString;
  80. #endregion
  81. #region Private Properties
  82. private bool PortalBinded
  83. {
  84. get
  85. {
  86. if(ViewState["PortalBinded"] == null)
  87. {
  88. return false;
  89. }
  90. return Convert.ToBoolean(ViewState["PortalBinded"]);
  91. }
  92. set
  93. {
  94. ViewState["PortalBinded"] = value;
  95. }
  96. }
  97. #endregion
  98. #region Protected Members
  99. protected Version ApplicationVersion
  100. {
  101. get
  102. {
  103. return DotNetNukeContext.Current.Application.Version;
  104. }
  105. }
  106. protected Version DatabaseVersion
  107. {
  108. get
  109. {
  110. return _dataBaseVersion ?? (_dataBaseVersion = DataProvider.Instance().GetVersion());
  111. }
  112. }
  113. protected Version BaseVersion
  114. {
  115. get
  116. {
  117. return Upgrade.Upgrade.GetInstallVersion(InstallTemplate);
  118. }
  119. }
  120. protected XmlDocument InstallTemplate
  121. {
  122. get
  123. {
  124. if (_installTemplate == null)
  125. {
  126. _installTemplate = new XmlDocument();
  127. Upgrade.Upgrade.GetInstallTemplate(_installTemplate);
  128. }
  129. return _installTemplate;
  130. }
  131. }
  132. protected bool PermissionsValid
  133. {
  134. get
  135. {
  136. bool valid = false;
  137. if (ViewState["PermissionsValid"] != null)
  138. {
  139. valid = Convert.ToBoolean(ViewState["PermissionsValid"]);
  140. }
  141. return valid;
  142. }
  143. set
  144. {
  145. ViewState["PermissionsValid"] = value;
  146. }
  147. }
  148. protected int PortalId
  149. {
  150. get
  151. {
  152. int portalId = Null.NullInteger;
  153. if (ViewState["PortalId"] != null)
  154. {
  155. portalId = Convert.ToInt32(ViewState["PortalId"]);
  156. }
  157. return portalId;
  158. }
  159. set
  160. {
  161. ViewState["PortalId"] = value;
  162. }
  163. }
  164. protected string Versions
  165. {
  166. get
  167. {
  168. string versions = Null.NullString;
  169. if (ViewState["Versions"] != null)
  170. {
  171. versions = Convert.ToString(ViewState["Versions"]);
  172. }
  173. return versions;
  174. }
  175. set
  176. {
  177. ViewState["Versions"] = value;
  178. }
  179. }
  180. #endregion
  181. #region IClientAPICallbackEventHandler Members
  182. public string RaiseClientAPICallbackEvent(string eventArgument)
  183. {
  184. return ProcessAction(eventArgument);
  185. }
  186. #endregion
  187. #region Private Methods
  188. /// -----------------------------------------------------------------------------
  189. /// <summary>
  190. /// BindAuthSystems binds the Authentication Systems checkbox list
  191. /// </summary>
  192. /// <remarks>
  193. /// </remarks>
  194. /// <history>
  195. /// [cnurse] 02/28/2008 Created
  196. /// </history>
  197. /// -----------------------------------------------------------------------------
  198. private void BindAuthSystems()
  199. {
  200. BindPackageItems("AuthSystem", lstAuthSystems, lblNoAuthSystems, "NoAuthSystems", AuthSystemsErrorLabel);
  201. }
  202. /// -----------------------------------------------------------------------------
  203. /// <summary>
  204. /// BindConnectionString binds the connection String info
  205. /// </summary>
  206. /// <remarks>
  207. /// </remarks>
  208. /// <history>
  209. /// [cnurse] 01/23/2007 Created
  210. /// </history>
  211. /// -----------------------------------------------------------------------------
  212. private void BindConnectionString()
  213. {
  214. string connection = Config.GetConnectionString();
  215. foreach (string connectionParam in connection.Split(';'))
  216. {
  217. int index = connectionParam.IndexOf("=");
  218. if (index > 0)
  219. {
  220. string key = connectionParam.Substring(0, index);
  221. string value = connectionParam.Substring(index + 1);
  222. switch (key.ToLower())
  223. {
  224. case "server":
  225. case "data source":
  226. case "address":
  227. case "addr":
  228. case "network address":
  229. txtServer.Text = value;
  230. break;
  231. case "database":
  232. case "initial catalog":
  233. txtDatabase.Text = value;
  234. break;
  235. case "uid":
  236. case "user id":
  237. case "user":
  238. txtUserId.Text = value;
  239. break;
  240. case "pwd":
  241. case "password":
  242. txtPassword.Text = value;
  243. break;
  244. case "integrated security":
  245. chkIntegrated.Checked = (value.ToLower() == "true");
  246. break;
  247. case "attachdbfilename":
  248. txtFile.Text = value.Replace("|DataDirectory|", "");
  249. break;
  250. }
  251. }
  252. }
  253. if (chkIntegrated.Checked)
  254. {
  255. chkOwner.Checked = true;
  256. }
  257. chkOwner.Enabled = !chkIntegrated.Checked;
  258. }
  259. /// -----------------------------------------------------------------------------
  260. /// <summary>
  261. /// Gets the userid for the upgradeConnectionString
  262. /// </summary>
  263. /// <remarks>
  264. /// </remarks>
  265. /// <history>
  266. /// [smehaffie] 07/13/2008 Created
  267. /// </history>
  268. /// -----------------------------------------------------------------------------
  269. private static string GetUpgradeConnectionStringUserID()
  270. {
  271. string dbUser = "";
  272. string connection = Config.GetUpgradeConnectionString();
  273. //If connection string does not use integrated security, then get user id.
  274. if (connection.ToLower().Contains("user id") || connection.ToLower().Contains("uid") || connection.ToLower().Contains("user"))
  275. {
  276. string[] connectionParams = connection.Split(';');
  277. foreach (string connectionParam in connectionParams)
  278. {
  279. int index = connectionParam.IndexOf("=");
  280. if (index > 0)
  281. {
  282. string key = connectionParam.Substring(0, index);
  283. string value = connectionParam.Substring(index + 1);
  284. if ("user id|uuid|user".Contains(key.Trim().ToLower()))
  285. {
  286. dbUser = value.Trim();
  287. }
  288. }
  289. }
  290. }
  291. return dbUser;
  292. }
  293. /// -----------------------------------------------------------------------------
  294. /// <summary>
  295. /// BindDatabases binds the supported databases
  296. /// </summary>
  297. /// <remarks>
  298. /// </remarks>
  299. /// <history>
  300. /// [cnurse] 02/23/2007 Created
  301. /// </history>
  302. /// -----------------------------------------------------------------------------
  303. private void BindDatabases()
  304. {
  305. if ((Config.GetDefaultProvider("data").Name == "SqlDataProvider"))
  306. {
  307. string connection = Config.GetConnectionString();
  308. if (connection.ToLower().Contains("attachdbfilename"))
  309. {
  310. rblDatabases.Items.FindByValue("SQLFile").Selected = true;
  311. }
  312. else
  313. {
  314. rblDatabases.Items.FindByValue("SQLDatabase").Selected = true;
  315. }
  316. }
  317. if ((Config.GetDefaultProvider("data").Name == "OracleDataProvider"))
  318. {
  319. rblDatabases.Items.Add(new ListItem(LocalizeString("Oracle"), "Oracle"));
  320. rblDatabases.SelectedIndex = 2;
  321. }
  322. }
  323. /// -----------------------------------------------------------------------------
  324. /// <summary>
  325. /// BindLanguages binds the languages checkbox list
  326. /// </summary>
  327. /// <remarks>
  328. /// </remarks>
  329. /// <history>
  330. /// [cnurse] 02/20/2007 Created
  331. /// </history>
  332. /// -----------------------------------------------------------------------------
  333. private void BindLanguages()
  334. {
  335. BindPackageItems("Language", lstLanguages, lblNoLanguages, "NoLanguages", languagesErrorLabel);
  336. }
  337. /// -----------------------------------------------------------------------------
  338. /// <summary>
  339. /// BindModules binds the modules checkbox list
  340. /// </summary>
  341. /// <remarks>
  342. /// </remarks>
  343. /// <history>
  344. /// [cnurse] 02/19/2007 Created
  345. /// </history>
  346. /// -----------------------------------------------------------------------------
  347. private void BindModules()
  348. {
  349. BindPackageItems("Module", lstModules, lblNoModules, "NoModules", modulesErrorLabel);
  350. }
  351. private void BindPackageItems(string packageType, CheckBoxList list, Label noItemsLabel, string noItemsKey, Label errorLabel)
  352. {
  353. string installPath = Globals.ApplicationMapPath + "\\Install\\" + packageType;
  354. list.Items.Clear();
  355. if (Directory.Exists(installPath))
  356. {
  357. string[] arrFiles = Directory.GetFiles(installPath);
  358. foreach (string strFile in arrFiles)
  359. {
  360. string strResource = strFile.Replace(installPath + "\\", "");
  361. if (strResource.ToLower().EndsWith(".zip") || strResource.ToLower().EndsWith(".resources"))
  362. {
  363. var packageItem = new ListItem();
  364. //*.zip packages are installed by default
  365. if (strResource.ToLower().EndsWith(".zip"))
  366. {
  367. packageItem.Selected = true;
  368. packageItem.Enabled = false;
  369. }
  370. else //*.resources packages will be optional
  371. {
  372. packageItem.Selected = false;
  373. packageItem.Enabled = true;
  374. }
  375. packageItem.Value = strResource;
  376. strResource = Regex.Replace(strResource, ".zip", "", RegexOptions.IgnoreCase);
  377. strResource = Regex.Replace(strResource, ".resources", "", RegexOptions.IgnoreCase);
  378. strResource = Regex.Replace(strResource, "_Install", ")", RegexOptions.IgnoreCase);
  379. strResource = Regex.Replace(strResource, "_Source", ")", RegexOptions.IgnoreCase);
  380. strResource = strResource.Replace("_0", " (0");
  381. packageItem.Text = strResource;
  382. list.Items.Add(packageItem);
  383. }
  384. }
  385. }
  386. if (list.Items.Count > 0)
  387. {
  388. noItemsLabel.Visible = false;
  389. }
  390. else
  391. {
  392. noItemsLabel.Visible = true;
  393. noItemsLabel.Text = LocalizeString(noItemsKey);
  394. }
  395. if (errorLabel != null)
  396. {
  397. errorLabel.Text = Null.NullString;
  398. }
  399. }
  400. /// -----------------------------------------------------------------------------
  401. /// <summary>
  402. /// BindPermissions binds the permissions checkbox list
  403. /// </summary>
  404. /// <remarks>
  405. /// </remarks>
  406. /// <history>
  407. /// [cnurse] 01/23/2007 Created
  408. /// </history>
  409. /// -----------------------------------------------------------------------------
  410. private void BindPermissions(bool test)
  411. {
  412. PermissionsValid = true;
  413. lstPermissions.Items.Clear();
  414. var permissionItem = new ListItem();
  415. var verifiers = new List<FileSystemPermissionVerifier>
  416. {
  417. new FileSystemPermissionVerifier(Server.MapPath("~")),
  418. new FileSystemPermissionVerifier(Server.MapPath("~/App_Data"))
  419. };
  420. //FolderCreate
  421. if (test && PermissionsValid)
  422. {
  423. permissionItem.Selected = verifiers.All(v => v.VerifyFolderCreate());
  424. PermissionsValid = PermissionsValid && permissionItem.Selected;
  425. }
  426. permissionItem.Enabled = false;
  427. permissionItem.Text = LocalizeString("FolderCreate");
  428. lstPermissions.Items.Add(permissionItem);
  429. //FileCreate
  430. permissionItem = new ListItem();
  431. if (test && PermissionsValid)
  432. {
  433. permissionItem.Selected = verifiers.All(v => v.VerifyFileCreate());
  434. PermissionsValid = PermissionsValid && permissionItem.Selected;
  435. }
  436. permissionItem.Enabled = false;
  437. permissionItem.Text = LocalizeString("FileCreate");
  438. lstPermissions.Items.Add(permissionItem);
  439. //FileDelete
  440. permissionItem = new ListItem();
  441. if (test && PermissionsValid)
  442. {
  443. permissionItem.Selected = verifiers.All(v => v.VerifyFileDelete());
  444. PermissionsValid = PermissionsValid && permissionItem.Selected;
  445. }
  446. permissionItem.Enabled = false;
  447. permissionItem.Text = LocalizeString("FileDelete");
  448. lstPermissions.Items.Add(permissionItem);
  449. //FolderDelete
  450. permissionItem = new ListItem();
  451. if (test && PermissionsValid)
  452. {
  453. permissionItem.Selected = verifiers.All(v => v.VerifyFolderDelete());
  454. PermissionsValid = PermissionsValid && permissionItem.Selected;
  455. }
  456. permissionItem.Enabled = false;
  457. permissionItem.Text = LocalizeString("FolderDelete");
  458. lstPermissions.Items.Add(permissionItem);
  459. if (test)
  460. {
  461. var paths = string.Join("; ", (from v in verifiers select v.BasePath).ToArray());
  462. permissionsErrorLabel.Text = PermissionsValid ? LocalizeString("PermissionsOk") : LocalizeString("PermissionsError").Replace("{0}", paths);
  463. }
  464. }
  465. /// -----------------------------------------------------------------------------
  466. /// <summary>
  467. /// BindPortal binds the portal information
  468. /// </summary>
  469. /// <remarks>
  470. /// </remarks>
  471. /// <history>
  472. /// [cnurse] 02/19/2007 Created
  473. /// </history>
  474. /// -----------------------------------------------------------------------------
  475. private void BindPortal()
  476. {
  477. if(PortalBinded)
  478. {
  479. return;
  480. }
  481. XmlNode portalNode = InstallTemplate.SelectSingleNode("//dotnetnuke/portals/portal");
  482. XmlNode superUserNode = InstallTemplate.SelectSingleNode("//dotnetnuke/superuser");
  483. if (portalNode != null)
  484. {
  485. if (superUserNode != null)
  486. {
  487. usrAdmin.FirstName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "firstname");
  488. usrAdmin.LastName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "lastname");
  489. usrAdmin.UserName = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "username");
  490. usrAdmin.Email = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "email");
  491. }
  492. txtPortalTitle.Text = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "portalname");
  493. string templateName = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "templatefile");
  494. BindTemplates(templateName);
  495. }
  496. adminUserErrorLabel.Text = Null.NullString;
  497. PortalBinded = true;
  498. }
  499. private class TemplateDisplayComparer : IComparer<PortalController.PortalTemplateInfo>
  500. {
  501. public int Compare(PortalController.PortalTemplateInfo x, PortalController.PortalTemplateInfo y)
  502. {
  503. var cultureCompare = String.Compare(x.CultureCode, y.CultureCode, StringComparison.CurrentCulture);
  504. if (cultureCompare == 0)
  505. {
  506. return String.Compare(x.Name, y.Name, StringComparison.CurrentCulture);
  507. }
  508. //put blank cultures last
  509. if (string.IsNullOrEmpty(x.CultureCode) || string.IsNullOrEmpty(y.CultureCode))
  510. {
  511. cultureCompare *= -1;
  512. }
  513. return cultureCompare;
  514. }
  515. }
  516. private void BindTemplates(string templateName)
  517. {
  518. var templates = TestablePortalController.Instance.GetAvailablePortalTemplates();
  519. templates = templates.OrderBy(x => x, new TemplateDisplayComparer()).ToList();
  520. foreach (var template in templates)
  521. {
  522. cboPortalTemplate.Items.Add(CreateListItem(template));
  523. }
  524. SelectADefaultTemplate(templates, templateName);
  525. if (cboPortalTemplate.Items.Count == 0)
  526. {
  527. UI.Skins.Skin.AddModuleMessage(this, "", Localization.Localization.GetString("PortalMissing", LocalResourceFile),
  528. ModuleMessage.ModuleMessageType.RedError);
  529. }
  530. cboPortalTemplate.Items.Insert(0, new ListItem(Localization.Localization.GetString("None_Specified"), "-1"));
  531. }
  532. private void SelectADefaultTemplate(IList<PortalController.PortalTemplateInfo> templates, string templateName)
  533. {
  534. string currentCulture = Thread.CurrentThread.CurrentUICulture.Name;
  535. var defaultTemplates =
  536. templates.Where(x => Path.GetFileName(x.TemplateFilePath) == templateName).ToList();
  537. var match = defaultTemplates.FirstOrDefault(x => x.CultureCode == currentCulture);
  538. if (match == null)
  539. {
  540. match = defaultTemplates.FirstOrDefault(x => x.CultureCode.StartsWith(currentCulture.Substring(0, 2)));
  541. }
  542. if (match == null)
  543. {
  544. match = defaultTemplates.FirstOrDefault(x => string.IsNullOrEmpty(x.CultureCode));
  545. }
  546. if (match != null)
  547. {
  548. cboPortalTemplate.SelectedIndex = templates.IndexOf(match);
  549. }
  550. }
  551. ListItem CreateListItem(PortalController.PortalTemplateInfo template)
  552. {
  553. string text, value;
  554. if (string.IsNullOrEmpty(template.CultureCode))
  555. {
  556. text = template.Name;
  557. value = Path.GetFileName(template.TemplateFilePath);
  558. }
  559. else
  560. {
  561. text = string.Format("{0} - {1}", template.Name, Localization.Localization.GetLocaleName(template.CultureCode, CultureDropDownTypes.NativeName));
  562. value = string.Format("{0}|{1}", Path.GetFileName(template.TemplateFilePath), template.CultureCode);
  563. }
  564. return new ListItem(text, value);
  565. }
  566. /// -----------------------------------------------------------------------------
  567. /// <summary>
  568. /// BindProviders binds the Providers checkbox list
  569. /// </summary>
  570. /// <remarks>
  571. /// </remarks>
  572. /// <history>
  573. /// [cnurse] 06/24/2008 Created
  574. /// </history>
  575. /// -----------------------------------------------------------------------------
  576. private void BindProviders()
  577. {
  578. BindPackageItems("Provider", lstProviders, lblNoProviders, "NoProviders", providersErrorLabel);
  579. }
  580. /// -----------------------------------------------------------------------------
  581. /// <summary>
  582. /// BindSkins binds the skins checkbox list
  583. /// </summary>
  584. /// <remarks>
  585. /// </remarks>
  586. /// <history>
  587. /// [cnurse] 02/16/2007 Created
  588. /// </history>
  589. /// -----------------------------------------------------------------------------
  590. private void BindSkins()
  591. {
  592. BindPackageItems("Skin", lstSkins, lblNoSkins, "NoSkins", skinsErrorLabel);
  593. BindPackageItems("Container", lstContainers, lblNoContainers, "NoContainers", null);
  594. }
  595. /// -----------------------------------------------------------------------------
  596. /// <summary>
  597. /// EnableButton enables/Disables a Navigation Button
  598. /// </summary>
  599. /// <remarks>
  600. /// </remarks>
  601. /// <history>
  602. /// [cnurse] 02/28/2007 Created
  603. /// </history>
  604. /// -----------------------------------------------------------------------------
  605. private static void EnableButton(LinkButton button, bool enabled)
  606. {
  607. if (button != null)
  608. {
  609. button.OnClientClick = "return !checkDisabled(this);";
  610. button.CssClass = enabled
  611. ? ((button.CommandName == "MoveNext") ? "dnnPrimaryAction" : "dnnSecondaryAction")
  612. : "dnnPrimaryAction dnnDisabledAction";
  613. }
  614. }
  615. /// -----------------------------------------------------------------------------
  616. /// <summary>
  617. /// GetInstallerLocales gets an ArrayList of the Locales
  618. /// </summary>
  619. /// <remarks>
  620. /// </remarks>
  621. /// <history>
  622. /// [cnurse] 01/23/2007 Created
  623. /// </history>
  624. /// -----------------------------------------------------------------------------
  625. private static ArrayList GetInstallerLocales()
  626. {
  627. var supportedLocales = new ArrayList();
  628. string filePath = Globals.ApplicationMapPath + LocalesFile.Replace("/", "\\");
  629. if (File.Exists(filePath))
  630. {
  631. var doc = new XPathDocument(filePath);
  632. foreach (XPathNavigator nav in doc.CreateNavigator().Select("root/language"))
  633. {
  634. if (nav.NodeType != XPathNodeType.Comment)
  635. {
  636. var objLocale = new Locale
  637. {
  638. Text = nav.GetAttribute("name", ""),
  639. Code = nav.GetAttribute("key", ""),
  640. Fallback = nav.GetAttribute("fallback", "")
  641. };
  642. supportedLocales.Add(objLocale);
  643. }
  644. }
  645. }
  646. else
  647. {
  648. var objLocale = new Locale
  649. {
  650. Text = "English",
  651. Code = "en-US",
  652. Fallback = ""
  653. };
  654. supportedLocales.Add(objLocale);
  655. }
  656. return supportedLocales;
  657. }
  658. /// -----------------------------------------------------------------------------
  659. /// <summary>
  660. /// GetNextScriptVersion gets the next script to Install
  661. /// </summary>
  662. /// <remarks>
  663. /// </remarks>
  664. /// <history>
  665. /// [cnurse] 02/15/2007 Created
  666. /// </history>
  667. /// -----------------------------------------------------------------------------
  668. private string GetNextScriptVersion(string strProviderPath, Version currentVersion)
  669. {
  670. string strNextVersion = "Done";
  671. if (currentVersion == null)
  672. {
  673. strNextVersion = GetBaseDatabaseVersion();
  674. }
  675. else
  676. {
  677. string strScriptVersion = Null.NullString;
  678. ArrayList arrScripts = Upgrade.Upgrade.GetUpgradeScripts(strProviderPath, currentVersion);
  679. if (arrScripts.Count > 0)
  680. {
  681. //First Script is next script
  682. strScriptVersion = Path.GetFileNameWithoutExtension(Convert.ToString(arrScripts[0]));
  683. }
  684. if (!string.IsNullOrEmpty(strScriptVersion))
  685. {
  686. strNextVersion = strScriptVersion;
  687. }
  688. }
  689. return strNextVersion;
  690. }
  691. /// -----------------------------------------------------------------------------
  692. /// <summary>
  693. /// GetWizardButton gets a wizard button from the template
  694. /// </summary>
  695. /// <remarks>
  696. /// </remarks>
  697. /// <history>
  698. /// [cnurse] 02/28/2007 Created
  699. /// </history>
  700. /// -----------------------------------------------------------------------------
  701. private LinkButton GetWizardButton(string containerID, string buttonID)
  702. {
  703. Control navContainer = wizInstall.FindControl(containerID);
  704. LinkButton button = null;
  705. if (navContainer != null)
  706. {
  707. button = navContainer.FindControl(buttonID) as LinkButton;
  708. }
  709. return button;
  710. }
  711. private void Initialise()
  712. {
  713. if (TestDataBaseInstalled())
  714. {
  715. //running current version, so redirect to site home page
  716. Response.Redirect("~/Default.aspx", true);
  717. }
  718. else
  719. {
  720. if (DatabaseVersion > new Version(0, 0, 0))
  721. {
  722. //Upgrade
  723. languagePanel.Visible = false;
  724. introTitleLabel.Text = string.Format(LocalizeString("UpgradeTitle"), ApplicationVersion.ToString(3));
  725. introDetailLabel.Text = string.Format(LocalizeString("Upgrade"), Upgrade.Upgrade.GetStringVersion(DatabaseVersion));
  726. }
  727. else
  728. {
  729. //Install
  730. UpdateMachineKey();
  731. }
  732. }
  733. }
  734. private bool InstallAuthSystems()
  735. {
  736. return InstallPackageItems("AuthSystem", lstAuthSystems, lblNoAuthSystems, "InstallAuthSystemError");
  737. }
  738. private string InstallDatabase()
  739. {
  740. string strErrorMessage;
  741. string strProviderPath = _dataProvider.GetProviderPath();
  742. if (!strProviderPath.StartsWith("ERROR:"))
  743. {
  744. //Install Base Version
  745. strErrorMessage = Upgrade.Upgrade.InstallDatabase(BaseVersion, strProviderPath, InstallTemplate, false);
  746. }
  747. else
  748. {
  749. //provider error
  750. strErrorMessage = strProviderPath;
  751. }
  752. if (string.IsNullOrEmpty(strErrorMessage))
  753. {
  754. //Get Next Version
  755. strErrorMessage = GetNextScriptVersion(strProviderPath, BaseVersion);
  756. }
  757. else if (!strErrorMessage.StartsWith("ERROR:"))
  758. {
  759. strErrorMessage = "ERROR: " + string.Format(LocalizeString("ScriptError"), Upgrade.Upgrade.GetLogFile(strProviderPath, BaseVersion));
  760. }
  761. return strErrorMessage;
  762. }
  763. private bool InstallHost()
  764. {
  765. bool success = false;
  766. try
  767. {
  768. //Initialise Host Settings
  769. Upgrade.Upgrade.InitialiseHostSettings(InstallTemplate, false);
  770. Upgrade.Upgrade.InstallFiles(InstallTemplate, false);
  771. if (!string.IsNullOrEmpty(txtSMTPServer.Text))
  772. {
  773. HostController.Instance.Update("SMTPServer", txtSMTPServer.Text);
  774. HostController.Instance.Update("SMTPAuthentication", optSMTPAuthentication.SelectedItem.Value);
  775. HostController.Instance.Update("SMTPUsername", txtSMTPUsername.Text, true);
  776. HostController.Instance.Update("SMTPPassword", txtSMTPPassword.Text, true);
  777. HostController.Instance.Update("SMTPEnableSSL", chkSMTPEnableSSL.Checked ? "Y" : "N");
  778. }
  779. //Clear Host Cache
  780. DataCache.ClearHostCache(false);
  781. success = true;
  782. }
  783. catch (Exception exc)
  784. {
  785. DnnLog.Error(exc);
  786. success = false;
  787. }
  788. return success;
  789. }
  790. private bool InstallLanguages()
  791. {
  792. return InstallPackageItems("Language", lstLanguages, languagesErrorLabel, "InstallLanguageError");
  793. }
  794. private bool InstallModules()
  795. {
  796. return InstallPackageItems("Module", lstModules, modulesErrorLabel, "InstallModuleError");
  797. }
  798. private bool InstallPackageItems(string packageType, CheckBoxList list, Label errorLabel, string errorKey)
  799. {
  800. bool success = false;
  801. string strErrorMessage = Null.NullString;
  802. //Get current Script time-out
  803. int scriptTimeOut = Server.ScriptTimeout;
  804. try
  805. {
  806. //Set Script timeout to MAX value
  807. Server.ScriptTimeout = int.MaxValue;
  808. string installPath = Globals.ApplicationMapPath + "\\Install\\" + packageType;
  809. foreach (ListItem packageItem in list.Items)
  810. {
  811. if (packageItem.Selected)
  812. {
  813. if ((File.Exists(installPath + "\\" + packageItem.Value)))
  814. {
  815. success = Upgrade.Upgrade.InstallPackage(installPath + "\\" + packageItem.Value, packageType, false);
  816. if (!success)
  817. {
  818. strErrorMessage += string.Format(LocalizeString(errorKey), packageItem.Text);
  819. }
  820. }
  821. }
  822. }
  823. success = string.IsNullOrEmpty(strErrorMessage) || packageType == "Language";
  824. }
  825. catch (Exception ex)
  826. {
  827. DnnLog.Error(ex);
  828. strErrorMessage = ex.StackTrace;
  829. }
  830. finally
  831. {
  832. //restore Script timeout
  833. Server.ScriptTimeout = scriptTimeOut;
  834. }
  835. if (!success)
  836. {
  837. errorLabel.Text += strErrorMessage;
  838. }
  839. return success;
  840. }
  841. private bool InstallPortal()
  842. {
  843. string strErrorMessage = usrAdmin.Validate();
  844. if (!string.IsNullOrEmpty(strErrorMessage))
  845. {
  846. string strError = LocalizeString(strErrorMessage);
  847. if (strErrorMessage == "PasswordLength")
  848. {
  849. strError = string.Format(strError, MembershipProviderConfig.MinPasswordLength);
  850. }
  851. adminUserErrorLabel.Text = string.Format(LocalizeString("AdminUserError"), strError);
  852. return false;
  853. }
  854. if(cboPortalTemplate.SelectedIndex == 0)
  855. {
  856. string error = LocalizeString("MustSelecteATemplate");
  857. adminUserErrorLabel.Text = error;
  858. return false;
  859. }
  860. bool success = false;
  861. try
  862. {
  863. string strServerPath = Globals.ApplicationMapPath + "\\";
  864. string strPortalAlias = Globals.GetDomainName(HttpContext.Current.Request, true).Replace("/Install", "");
  865. PortalController.PortalTemplateInfo template = LoadPortalTemplateInfoForSelectedItem();
  866. UserInfo adminUser = CreateUserInfo();
  867. if (template.CultureCode != "en-US")
  868. {
  869. //Check if language is installed
  870. var locale = LocaleController.Instance.GetLocale(template.CultureCode);
  871. //If not installed - install it
  872. if (locale == null)
  873. {
  874. string installPath = Globals.ApplicationMapPath + "\\Install\\Language";
  875. string languagePack = String.Format(installPath + "\\ResourcePack.Full.{0}.{1}.resources", Globals.FormatVersion(ApplicationVersion, "00", 3, "."), template.CultureCode);
  876. if (File.Exists(languagePack))
  877. {
  878. success = Upgrade.Upgrade.InstallPackage(languagePack, "Language", false);
  879. }
  880. }
  881. }
  882. //Create Portal
  883. PortalId = TestablePortalController.Instance.CreatePortal(txtPortalTitle.Text,
  884. adminUser,
  885. "",
  886. "",
  887. template,
  888. "",
  889. strPortalAlias,
  890. strServerPath,
  891. "",
  892. false);
  893. success = (PortalId > Null.NullInteger);
  894. if (template.CultureCode != "en-US")
  895. {
  896. var locale = LocaleController.Instance.GetLocale("en-US");
  897. //remove en-US from portal
  898. Localization.Localization.RemoveLanguageFromPortal(PortalId, locale.LanguageId);
  899. }
  900. //Set admin user to be a superuser
  901. adminUser = UserController.GetUserByName(PortalId, usrAdmin.UserName);
  902. adminUser.IsSuperUser = true;
  903. UserController.UpdateUser(PortalId, adminUser);
  904. //Log user in to site
  905. UserLoginStatus loginStatus = UserLoginStatus.LOGIN_FAILURE;
  906. UserController.UserLogin(PortalId, usrAdmin.UserName, usrAdmin.Password, "", "", "", ref loginStatus, false);
  907. Config.Touch();
  908. Response.Redirect("~/Default.aspx", true);
  909. }
  910. catch (ThreadAbortException)
  911. {
  912. //do nothing - we swallow this exception - becuase of redirect
  913. }
  914. catch (Exception ex)
  915. {
  916. DnnLog.Error(ex);
  917. success = false;
  918. strErrorMessage = ex.Message;
  919. }
  920. if (!success)
  921. {
  922. adminUserErrorLabel.Text = string.Format(LocalizeString("InstallPortalError"), strErrorMessage);
  923. }
  924. return success;
  925. }
  926. private UserInfo CreateUserInfo()
  927. {
  928. var adminUser = new UserInfo();
  929. adminUser.FirstName = usrAdmin.FirstName;
  930. adminUser.LastName = usrAdmin.LastName;
  931. adminUser.Username = usrAdmin.UserName;
  932. adminUser.DisplayName = usrAdmin.FirstName + " " + usrAdmin.LastName;
  933. adminUser.Membership.Password = usrAdmin.Password;
  934. adminUser.Email = usrAdmin.Email;
  935. adminUser.IsSuperUser = false;
  936. adminUser.Membership.Approved = true;
  937. adminUser.Profile.FirstName = usrAdmin.FirstName;
  938. adminUser.Profile.LastName = usrAdmin.LastName;
  939. return adminUser;
  940. }
  941. PortalController.PortalTemplateInfo LoadPortalTemplateInfoForSelectedItem()
  942. {
  943. var values = cboPortalTemplate.SelectedItem.Value.Split('|');
  944. return TestablePortalController.Instance.GetPortalTemplate(Path.Combine(TestableGlobals.Instance.HostMapPath, values[0]), values.Length > 1 ? values[1] : null);
  945. }
  946. private bool InstallProviders()
  947. {
  948. return InstallPackageItems("Provider", lstProviders, providersErrorLabel, "InstallProviderError");
  949. }
  950. private bool InstallSkins()
  951. {
  952. bool skinSuccess = InstallPackageItems("Skin", lstSkins, skinsErrorLabel, "InstallSkinError");
  953. bool containerSuccess = InstallPackageItems("Container", lstContainers, skinsErrorLabel, "InstallContainerError");
  954. return skinSuccess && containerSuccess;
  955. }
  956. private string InstallVersion(string strVersion)
  957. {
  958. string strErrorMessage = Null.NullString;
  959. var version = new Version(strVersion);
  960. string strScriptFile = Null.NullString;
  961. string strProviderPath = _dataProvider.GetProviderPath();
  962. if (!strProviderPath.StartsWith("ERROR:"))
  963. {
  964. //Install Version
  965. strScriptFile = Upgrade.Upgrade.GetScriptFile(strProviderPath, version);
  966. strErrorMessage += Upgrade.Upgrade.UpgradeVersion(strScriptFile, false);
  967. Versions += "," + strVersion;
  968. }
  969. else
  970. {
  971. //provider error
  972. strErrorMessage = strProviderPath;
  973. }
  974. if (string.IsNullOrEmpty(strErrorMessage))
  975. {
  976. //Get Next Version
  977. strErrorMessage = GetNextScriptVersion(strProviderPath, version);
  978. }
  979. else
  980. {
  981. strErrorMessage = "ERROR: (see " + Path.GetFileName(strScriptFile).Replace("." + Upgrade.Upgrade.DefaultProvider, ".log") + " for more information)";
  982. }
  983. return strErrorMessage;
  984. }
  985. /// -----------------------------------------------------------------------------
  986. /// <summary>
  987. /// LocalizePage sets up the Localized Text
  988. /// </summary>
  989. /// <remarks>
  990. /// </remarks>
  991. /// <history>
  992. /// [cnurse] 02/09/2007 Created
  993. /// </history>
  994. /// -----------------------------------------------------------------------------
  995. private void LocalizePage()
  996. {
  997. //Main Title
  998. Title = LocalizeString("Title") + @" - " + LocalizeString("Page" + wizInstall.ActiveStepIndex + ".Title");
  999. //Page Titles
  1000. for (int i = 0; i <= wizInstall.WizardSteps.Count - 1; i++)
  1001. {
  1002. wizInstall.WizardSteps[i].Title = LocalizeString("Page" + i + ".Title");
  1003. }
  1004. //Wizard Buttons
  1005. LinkButton nextButton = GetWizardButton("StepNavigationTemplateContainerID", "StepNextButton");
  1006. nextButton.Text = LocalizeString("Next");
  1007. nextButton = GetWizardButton("StartNavigationTemplateContainerID", "StartNextButton");
  1008. nextButton.Text = LocalizeString("Next");
  1009. LinkButton previousButton = GetWizardButton("StepNavigationTemplateContainerID", "StepPreviousButton");
  1010. previousButton.Text = LocalizeString("Previous");
  1011. switch (wizInstall.ActiveStepIndex)
  1012. {
  1013. case 0: //Page 0 - Welcome
  1014. introTitleLabel.Text = string.Format(LocalizeString("IntroTitle"), Globals.FormatVersion(ApplicationVersion));
  1015. introDetailLabel.Text = LocalizeString("IntroDetail");
  1016. installTypeRadioButton.Items[0].Text = LocalizeString("Typical");
  1017. installTypeRadioButton.Items[1].Text = LocalizeString("Full");
  1018. installTypeRadioButton.Items[2].Text = LocalizeString("Auto");
  1019. break;
  1020. case 1: //Page 1 - File Permissions
  1021. BindPermissions(false);
  1022. LinkButton customButton = GetWizardButton("StepNavigationTemplateContainerID", "CustomButton");
  1023. customButton.Text = LocalizeString("TestPerm");
  1024. break;
  1025. case 2://Page 2 - Database Configuration
  1026. databaseConfigTitleLabel.Text = LocalizeString("DatabaseConfigTitle");
  1027. databaseConfigDetailLabel.Text = LocalizeString("DatabaseConfigDetail");
  1028. rblDatabases.Items[0].Text = LocalizeString("SQLServerXPress");
  1029. rblDatabases.Items[1].Text = LocalizeString("SQLServer");
  1030. break;
  1031. case 3: //Page 3 - Database Installation
  1032. databaseInstallTitleLabel.Text = LocalizeString("DatabaseInstallTitle");
  1033. databaseInstallDetailLabel.Text = LocalizeString("DatabaseInstallDetail");
  1034. break;
  1035. case 4: //Page 4 - Modules
  1036. modulesTitleLabel.Text = LocalizeString("ModulesTitle");
  1037. modulesDetailLabel.Text = LocalizeString("ModulesDetail");
  1038. lblModules.Text = LocalizeString("Modules");
  1039. break;
  1040. case 5: //Page 5 - Skins/Conatiners
  1041. skinsTitleLabel.Text = LocalizeString("SkinsTitle");
  1042. skinsDetailLabel.Text = LocalizeString("SkinsDetail");
  1043. lblSkins.Text = LocalizeString("Skins");
  1044. lblContainers.Text = LocalizeString("Containers");
  1045. break;
  1046. case 6: //Page 6 - Languages
  1047. languagesTitleLabel.Text = LocalizeString("LanguagesTitle");
  1048. languagesDetailLabel.Text = LocalizeString("LanguagesDetail");
  1049. lblLanguages.Text = LocalizeString("Languages");
  1050. break;
  1051. case 7: //Page 7 - Auth Systems
  1052. authSystemsTitleLabel.Text = LocalizeString("AuthSystemsTitle");
  1053. authSystemDetailLabel.Text = LocalizeString("AuthSystemsDetail");
  1054. lblAuthSystems.Text = LocalizeString("AuthSystems");
  1055. break;
  1056. case 8: //Page 8 - Providers
  1057. providersTitleLabel.Text = LocalizeString("ProvidersTitle");
  1058. providersDetailLabel.Text = LocalizeString("ProvidersDetail");
  1059. lblProviders.Text = LocalizeString("Providers");
  1060. break;
  1061. case 9: //Page 9 - User/Portal Configuration
  1062. adminUserTitleLabel.Text = LocalizeString("AdminUserTitle");
  1063. adminUserDetailLabel.Text = LocalizeString("AdminUserDetail");
  1064. usrAdmin.FirstNameLabel = LocalizeString("FirstName");
  1065. usrAdmin.LastNameLabel = LocalizeString("LastName");
  1066. usrAdmin.UserNameLabel = LocalizeString("UserName");
  1067. usrAdmin.PasswordLabel = LocalizeString("Password");
  1068. usrAdmin.ConfirmLabel = LocalizeString("Confirm");
  1069. usrAdmin.EmailLabel = LocalizeString("Email");
  1070. lblAdminUser.Text = LocalizeString("AdminUser");
  1071. lblPortal.Text = LocalizeString("Portal");
  1072. portalDetailLabel.Text = LocalizeString("PortalDetail");
  1073. lblSMTPSettings.Text = LocalizeString("SMTPSettings");
  1074. lblSMTPSettingsHelp.Text = LocalizeString("SMTPSettingsHelp");
  1075. break;
  1076. }
  1077. }
  1078. private void SetupDatabasePage()
  1079. {
  1080. if (rblDatabases.SelectedIndex > Null.NullInteger)
  1081. {
  1082. bool isSQLFile = (rblDatabases.SelectedValue == "SQLFile");
  1083. bool isSQLDb = (rblDatabases.SelectedValue == "SQLDatabase");
  1084. bool isOracle = (rblDatabases.SelectedValue == "Oracle");
  1085. databasePanel.Visible = true;
  1086. fileRow.Visible = isSQLFile;
  1087. databaseRow.Visible = isSQLDb;
  1088. integratedRow.Visible = !isOracle;
  1089. userRow.Visible = !chkIntegrated.Checked || isOracle;
  1090. passwordRow.Visible = !chkIntegrated.Checked || isOracle;
  1091. chkOwner.Enabled = isSQLDb;
  1092. chkOwner.Checked = (Config.GetDataBaseOwner() == "dbo.");
  1093. txtqualifier.Text = Config.GetObjectQualifer();
  1094. }
  1095. else
  1096. {
  1097. databasePanel.Visible = false;
  1098. }
  1099. }
  1100. /// -----------------------------------------------------------------------------
  1101. /// <summary>
  1102. /// SetupPage updates the WizardPage
  1103. /// </summary>
  1104. /// <remarks>
  1105. /// </remarks>
  1106. /// <history>
  1107. /// [cnurse] 01/23/2007 Created
  1108. /// </history>
  1109. /// -----------------------------------------------------------------------------
  1110. private void SetupPage()
  1111. {
  1112. LinkButton nextButton = GetWizardButton("StepNavigationTemplateContainerID", "StepNextButton");
  1113. LinkButton prevButton = GetWizardButton("StepNavigationTemplateContainerID", "StepPreviousButton");
  1114. LinkButton customButton = GetWizardButton("StepNavigationTemplateContainerID", "CustomButton");
  1115. EnableButton(nextButton, true);
  1116. EnableButton(prevButton, true);
  1117. ShowButton(customButton, false);
  1118. switch (wizInstall.ActiveStepIndex)
  1119. {
  1120. case 0: //Page 0 - Welcome
  1121. permissionsErrorLabel.Text = "";
  1122. break;
  1123. case 1:
  1124. databaseErrorLabel.Text = "";
  1125. ShowButton(customButton, true);
  1126. break;
  1127. case 2: //Page 2 - Database Configuration
  1128. permissionsErrorLabel.Text = "";
  1129. SetupDatabasePage();
  1130. break;
  1131. case 3:
  1132. databaseErrorLabel.Text = "";
  1133. installErrorLabel.Text = "";
  1134. installErrorLabel.Visible = false;
  1135. EnableButton(nextButton, false);
  1136. ShowButton(prevButton, false);
  1137. break;
  1138. case 4: //Page 4 - Modules
  1139. BindModules();
  1140. ShowButton(prevButton, false);
  1141. break;
  1142. case 5: //Page 5 - Skins/Conatiners
  1143. BindSkins();
  1144. ShowButton(prevButton, false);
  1145. break;
  1146. case 6: //Page 6 - Languages
  1147. BindLanguages();
  1148. ShowButton(prevButton, false);
  1149. break;
  1150. case 7: //Page 7 - Auth Systems
  1151. BindAuthSystems();
  1152. ShowButton(prevButton, false);
  1153. break;
  1154. case 8: //Page 8 - Providers
  1155. BindProviders();
  1156. ShowButton(prevButton, false);
  1157. break;
  1158. case 9: //Page 9 - User/Portal Configuration
  1159. // BindSuperUser();
  1160. // ShowButton(prevButton, false);
  1161. // break;
  1162. //case 10: //Page 10 - Portal
  1163. BindPortal();
  1164. ShowButton(prevButton, false);
  1165. break;
  1166. }
  1167. }
  1168. /// -----------------------------------------------------------------------------
  1169. /// <summary>
  1170. /// ShowButton shows/hides a Navigation Button
  1171. /// </summary>
  1172. /// <remarks>
  1173. /// </remarks>
  1174. /// <history>
  1175. /// [cnurse] 02/28/2007 Created
  1176. /// </history>
  1177. /// -----------------------------------------------------------------------------
  1178. private static void ShowButton(LinkButton button, bool enabled)
  1179. {
  1180. if (button != null)
  1181. {
  1182. button.Visible = enabled;
  1183. }
  1184. }
  1185. /// -----------------------------------------------------------------------------
  1186. /// <summary>
  1187. /// TestDatabaseConnection checks the Database connection properties provided
  1188. /// </summary>
  1189. /// <remarks>
  1190. /// </remarks>
  1191. /// <history>
  1192. /// [cnurse] 01/23/2007 Created
  1193. /// </history>
  1194. /// -----------------------------------------------------------------------------
  1195. private bool TestDatabaseConnection()
  1196. {
  1197. bool success = false;
  1198. if (string.IsNullOrEmpty(rblDatabases.SelectedValue))
  1199. {
  1200. _connectionString = "ERROR:" + LocalizeString("ChooseDbError");
  1201. }
  1202. else
  1203. {
  1204. bool isSQLFile = (rblDatabases.SelectedValue == "SQLFile");
  1205. bool isOracle = (rblDatabases.SelectedValue == "Oracle");
  1206. DbConnectionStringBuilder builder = _dataProvider.GetConnectionStringBuilder();
  1207. if (!string.IsNullOrEmpty(txtServer.Text))
  1208. {
  1209. builder["Data Source"] = txtServer.Text;
  1210. }
  1211. if (!string.IsNullOrEmpty(txtDatabase.Text) && !isSQLFile)
  1212. {
  1213. builder["Initial Catalog"] = txtDatabase.Text;
  1214. }
  1215. if (string.IsNullOrEmpty(txtDatabase.Text) && !isSQLFile)
  1216. {
  1217. databaseErrorLabel.Text = LocalizeString("DbNameError");
  1218. if (!isOracle) return false;
  1219. }
  1220. if (!string.IsNullOrEmpty(txtFile.Text) && isSQLFile)
  1221. {
  1222. builder["attachdbfilename"] = "|DataDirectory|" + txtFile.Text;
  1223. }
  1224. if (chkIntegrated.Checked)
  1225. {
  1226. builder["integrated security"] = "true";
  1227. }
  1228. if (!string.IsNullOrEmpty(txtUserId.Text))
  1229. {
  1230. builder["uid"] = txtUserId.Text;
  1231. }
  1232. if (!string.IsNullOrEmpty(txtPassword.Text))
  1233. {
  1234. builder["pwd"] = txtPassword.Text;
  1235. }
  1236. if (isSQLFile)
  1237. {
  1238. builder["user instance"] = "true";
  1239. }
  1240. string owner = txtUserId.Text + ".";
  1241. if (chkOwner.Checked)
  1242. {
  1243. owner = "dbo.";
  1244. }
  1245. _connectionString = DataProvider.Instance().TestDatabaseConnection(builder, owner, txtqualifier.Text);
  1246. }
  1247. if (_connectionString.StartsWith("ERROR:"))
  1248. {
  1249. databaseErrorLabel.Text = string.Format(LocalizeString("ConnectError"), _connectionString.Replace("ERROR:", ""));
  1250. }
  1251. else
  1252. {
  1253. success = true;
  1254. databaseErrorLabel.Text = LocalizeString("ConnectSuccess");
  1255. }
  1256. return success;
  1257. }
  1258. /// -----------------------------------------------------------------------------
  1259. /// <summary>
  1260. /// TestDataBaseInstalled checks whether the Database is the current version
  1261. /// </summary>
  1262. /// <remarks>
  1263. /// </remarks>
  1264. /// <history>
  1265. /// [cnurse] 02/16/2007 Created
  1266. /// </history>
  1267. /// -----------------------------------------------------------------------------
  1268. private bool TestDataBaseInstalled()
  1269. {
  1270. bool success = true;
  1271. if (DatabaseVersion == null || DatabaseVersion.Major != ApplicationVersion.Major || DatabaseVersion.Minor != ApplicationVersion.Minor || DatabaseVersion.Build != ApplicationVersion.Build)
  1272. {
  1273. success = false;
  1274. }
  1275. if (!success)
  1276. {
  1277. installErrorLabel.Text = LocalizeString("Install.Error");
  1278. }
  1279. return success;
  1280. }
  1281. private bool TestSMTPSettings()
  1282. {
  1283. if (!string.IsNullOrEmpty(usrAdmin.Email))
  1284. {
  1285. try
  1286. {
  1287. var emailMessage = new MailMessage(usrAdmin.Email, usrAdmin.Email, LocalizeString("EmailTestMessageSubject"), string.Empty);
  1288. var smtpClient = new SmtpClient(txtSMTPServer.Text);
  1289. string[] smtpHostParts = txtSMTPServer.Text.Split(':');
  1290. if (smtpHostParts.Length > 1)
  1291. {
  1292. smtpClient.Host = smtpHostParts[0];
  1293. smtpClient.Port = Convert.ToInt32(smtpHostParts[1]);
  1294. }
  1295. switch (optSMTPAuthentication.SelectedItem.Value)
  1296. {
  1297. case "":
  1298. case "0":
  1299. // anonymous
  1300. break;
  1301. case "1":
  1302. // basic
  1303. if (!string.IsNullOrEmpty(txtSMTPUsername.Text) && !string.IsNullOrEmpty(txtSMTPPassword.Text))
  1304. {
  1305. smtpClient.UseDefaultCredentials = false;
  1306. smtpClient.Credentials = new NetworkCredential(txtSMTPUsername.Text, txtSMTPPassword.Text);
  1307. }
  1308. break;
  1309. case "2":
  1310. // NTLM
  1311. smtpClient.UseDefaultCredentials = true;
  1312. break;
  1313. }
  1314. smtpClient.EnableSsl = chkSMTPEnableSSL.Checked;
  1315. smtpClient.Send(emailMessage);
  1316. adminUserErrorLabel.Text = string.Format(LocalizeString("SMTPSuccess"), LocalizeString("EmailSentMessage"));
  1317. return true;
  1318. }
  1319. catch (Exception ex)
  1320. {
  1321. DnnLog.Error(ex);
  1322. adminUserErrorLabel.Text = string.Format(LocalizeString("SMTPError"), string.Format(LocalizeString("EmailErrorMessage"), ex.Message));
  1323. return false;
  1324. }
  1325. }
  1326. adminUserErrorLabel.Text = string.Format(LocalizeString("SMTPError"), LocalizeString("SpecifyHostEmailMessage"));
  1327. return false;
  1328. }
  1329. private void UpdateMachineKey()
  1330. {
  1331. string installationDate = Config.GetSetting("InstallationDate");
  1332. if (installationDate == null || String.IsNullOrEmpty(installationDate))
  1333. {
  1334. string strError = Config.UpdateMachineKey();
  1335. if (String.IsNullOrEmpty(strError))
  1336. {
  1337. //send a new request to the application to initiate step 2
  1338. Response.Redirect(HttpContext.Current.Request.RawUrl, true);
  1339. }
  1340. else
  1341. {
  1342. //403-3 Error - Redirect to ErrorPage
  1343. string strURL = "~/ErrorPage.aspx?status=403_3&error=" + strError;
  1344. HttpContext.Current.Response.Clear();
  1345. HttpContext.Current.Server.Transfer(strURL);
  1346. }
  1347. }
  1348. }
  1349. #endregion
  1350. #region Protected Methods
  1351. /// -----------------------------------------------------------------------------
  1352. /// <summary>
  1353. /// GetBaseDataBaseVersion gets the Base Database Version as a string
  1354. /// </summary>
  1355. /// <remarks>
  1356. /// </remarks>
  1357. /// <history>
  1358. /// [cnurse] 03/02/2007 Created
  1359. /// </history>
  1360. /// -----------------------------------------------------------------------------
  1361. protected string GetBaseDatabaseVersion()
  1362. {
  1363. return Upgrade.Upgrade.GetStringVersion(BaseVersion);
  1364. }
  1365. /// -----------------------------------------------------------------------------
  1366. /// <summary>
  1367. /// LocalizeString is a helper function for localizing strings
  1368. /// </summary>
  1369. /// <remarks>
  1370. /// </remarks>
  1371. /// <history>
  1372. /// [cnurse] 01/23/2007 Created
  1373. /// </history>
  1374. /// -----------------------------------------------------------------------------
  1375. protected string LocalizeString(string key)
  1376. {
  1377. return Localization.Localization.GetString(key, LocalResourceFile, cboLanguages.SelectedValue.ToLower());
  1378. }
  1379. protected override void OnError(EventArgs e)
  1380. {
  1381. HttpContext.Current.Response.Clear();
  1382. HttpContext.Current.Server.Transfer("~/ErrorPage.aspx");
  1383. }
  1384. #endregion
  1385. #region Event Handlers
  1386. /// -----------------------------------------------------------------------------
  1387. /// <summary>
  1388. /// Page_Init runs when the Page is initialised
  1389. /// </summary>
  1390. /// <remarks>
  1391. /// </remarks>
  1392. /// <history>
  1393. /// [cnurse] 02/14/2007 Created
  1394. /// </history>
  1395. /// -----------------------------------------------------------------------------
  1396. protected override void OnInit(EventArgs e)
  1397. {
  1398. base.OnInit(e);
  1399. cboLanguages.SelectedIndexChanged += cboLanguages_SelectedIndexChanged;
  1400. chkIntegrated.CheckedChanged += chkIntegrated_CheckedChanged;
  1401. rblDatabases.SelectedIndexChanged += rblDatabases_SelectedIndexChanged;
  1402. wizInstall.ActiveStepChanged += wizInstall_ActiveStepChanged;
  1403. wizInstall.NextButtonClick += wizInstall_NextButtonClick;
  1404. ClientAPI.HandleClientAPICallbackEvent(this);
  1405. }
  1406. /// -----------------------------------------------------------------------------
  1407. /// <summary>
  1408. /// Page_Load runs when the Page loads
  1409. /// </summary>
  1410. /// <remarks>
  1411. /// </remarks>
  1412. /// <history>
  1413. /// [cnurse] 02/09/2007 Created
  1414. /// </history>
  1415. /// -----------------------------------------------------------------------------
  1416. protected override void OnLoad(EventArgs e)
  1417. {
  1418. base.OnLoad(e);
  1419. //Register jquery reference.
  1420. jQuery.RequestRegistration();
  1421. //register variable ActionCallback with script necessary to perform callback
  1422. //[ACTIONTOKEN] will be replaced on the client side with real action
  1423. ClientAPI.RegisterClientVariable(Page, "ActionCallback", ClientAPI.GetCallbackEventReference(this, "[ACTIONTOKEN]", "successFunc", "this", "errorFunc"), true);
  1424. hostWarningLabel.Visible = !Regex.IsMatch(Request.Url.Host, "^([a-zA-Z0-9.-]+)$", RegexOptions.IgnoreCase);
  1425. //update current thread culture to make dnn label work correctly
  1426. Thread.CurrentThread.CurrentUICulture = new CultureInfo(cboLanguages.SelectedValue);
  1427. if (!Page.IsPostBack)
  1428. {
  1429. //Adding ClientDependency Resources config to web.config
  1430. BindPermissions(true);
  1431. if (PermissionsValid && !ClientResourceManager.IsInstalled())
  1432. {
  1433. ClientResourceManager.AddConfiguration();
  1434. Response.Redirect(Request.RawUrl);
  1435. }
  1436. installTypeRadioButton.Items.Clear();
  1437. installTypeRadioButton.Items.Add(new ListItem(LocalizeString("Typical"), "Typical"));
  1438. installTypeRadioButton.Items.Add(new ListItem(LocalizeString("Full"), "Full"));
  1439. installTypeRadioButton.Items.Add(new ListItem(LocalizeString("Auto"), "Auto"));
  1440. installTypeRadioButton.SelectedIndex = 0;
  1441. rblDatabases.Items.Clear();
  1442. rblDatabases.Items.Add(new ListItem(LocalizeString("SQLServerXPress"), "SQLFile"));
  1443. rblDatabases.Items.Add(new ListItem(LocalizeString("SQLServer"), "SQLDatabase"));
  1444. //Parse the conneection String to the form
  1445. BindConnectionString();
  1446. //Database Choices
  1447. BindDatabases();
  1448. if (TestDatabaseConnection())
  1449. {
  1450. Initialise();
  1451. installTypeRadioButton.Items[2].Enabled = true;
  1452. databaseWarningLabel.Visible = false;
  1453. }
  1454. else
  1455. {
  1456. //Install but connection string not configured to point at a valid SQL Server
  1457. UpdateMachineKey();
  1458. installTypeRadioButton.Items[2].Enabled = false;
  1459. databaseWarningLabel.Visible = true;
  1460. }
  1461. cboLanguages.DataSource = GetInstallerLocales();
  1462. cboLanguages.DataBind();
  1463. SelectBrowserLanguage();
  1464. wizInstall.ActiveStepIndex = 0;
  1465. LocalizePage();
  1466. SetupPage();
  1467. }
  1468. }
  1469. private void SelectBrowserLanguage()
  1470. {
  1471. var codes = cboLanguages.Items.Cast<ListItem>().Select(x => x.Value);
  1472. string cultureCode = TestableLocalization.Instance.BestCultureCodeBasedOnBrowserLanguages(codes);
  1473. cboLanguages.Items.FindByValue(cultureCode).Selected = true;
  1474. }
  1475. /// -----------------------------------------------------------------------------
  1476. /// <summary>
  1477. /// Page_PreRender runs just before the page is rendered
  1478. /// </summary>
  1479. /// <remarks>
  1480. /// </remarks>
  1481. /// <history>
  1482. /// [cnurse] 02/15/2007 Created
  1483. /// </history>
  1484. /// -----------------------------------------------------------------------------
  1485. protected override void OnPreRenderComplete(EventArgs e)
  1486. {
  1487. base.OnPreRenderComplete(e);
  1488. //Make sure that the password is not cleared on pastback
  1489. txtPassword.Attributes["value"] = txtPassword.Text;
  1490. txtSMTPPassword.Attributes["value"] = txtSMTPPassword.Text;
  1491. }
  1492. // ReSharper disable InconsistentNaming
  1493. /// -----------------------------------------------------------------------------
  1494. /// <summary>
  1495. /// Runs when the Selected Language is changed
  1496. /// </summary>
  1497. /// <remarks>
  1498. /// </remarks>
  1499. /// <history>
  1500. /// [cnurse] 02/09/2007 Created
  1501. /// </history>
  1502. /// -----------------------------------------------------------------------------
  1503. protected void cboLanguages_SelectedIndexChanged(object sender, EventArgs e)
  1504. {
  1505. LocalizePage();
  1506. }
  1507. /// -----------------------------------------------------------------------------
  1508. /// <summary>
  1509. /// Runs when the Integrated Security Checkbox value is changed
  1510. /// </summary>
  1511. /// <remarks>
  1512. /// </remarks>
  1513. /// <history>
  1514. /// [cnurse] 02/23/2007 Created
  1515. /// </history>
  1516. /// -----------------------------------------------------------------------------
  1517. protected void chkIntegrated_CheckedChanged(object sender, EventArgs e)
  1518. {
  1519. userRow.Visible = !chkIntegrated.Checked;
  1520. passwordRow.Visible = !chkIntegrated.Checked;
  1521. if (chkIntegrated.Checked)
  1522. {
  1523. chkOwner.Checked = true;
  1524. }
  1525. chkOwner.Enabled = !chkIntegrated.Checked;
  1526. LocalizePage();
  1527. }
  1528. protected void customButton_Click(object sender, EventArgs e)
  1529. {
  1530. BindPermissions(true);
  1531. }
  1532. /// -----------------------------------------------------------------------------
  1533. /// <summary>
  1534. /// Runs when there is a ClientCallback
  1535. /// </summary>
  1536. /// <remarks>
  1537. /// </remarks>
  1538. /// <history>
  1539. /// [cnurse] 02/09/2007 Created
  1540. /// </history>
  1541. /// -----------------------------------------------------------------------------
  1542. public string ProcessAction(string someAction)
  1543. {
  1544. //First check that we are not being targetted by an AJAX HttpPost, so get the current DB version
  1545. string strProviderPath = _dataProvider.GetProviderPath();
  1546. string nextVersion = GetNextScriptVersion(strProviderPath, DatabaseVersion);
  1547. if (someAction != nextVersion)
  1548. {
  1549. Exceptions.Exceptions.LogException(new Exception("Attempt made to run a Database Script - Possible Attack"));
  1550. return "Error: Possible Attack";
  1551. }
  1552. if (someAction == GetBaseDatabaseVersion())
  1553. {
  1554. string result = InstallDatabase();
  1555. if (result == "Done")
  1556. {
  1557. //Complete Installation
  1558. Upgrade.Upgrade.UpgradeApplication();
  1559. }
  1560. return result;
  1561. }
  1562. else if (someAction.Contains("."))
  1563. {
  1564. //Upgrade Database
  1565. string result = InstallVersion(someAction);
  1566. if (result == "Done")
  1567. {
  1568. ArrayList arrVersions = Upgrade.Upgrade.GetUpgradeScripts(strProviderPath, BaseVersion);
  1569. string strErrorMessage = Null.NullString;
  1570. for (int i = 0; i <= arrVersions.Count - 1; i++)
  1571. {
  1572. string strVersion = Path.GetFileNameWithoutExtension(Convert.ToString(arrVersions[i]));
  1573. var version = new Version(strVersion);
  1574. if (version != null)
  1575. {
  1576. strErrorMessage += Upgrade.Upgrade.UpgradeApplication(strProviderPath, version, false);
  1577. //delete files which are no longer used
  1578. strErrorMessage += Upgrade.Upgrade.DeleteFiles(strProviderPath, version, false);
  1579. //execute config file updates
  1580. strErrorMessage += Upgrade.Upgrade.UpdateConfig(strProviderPath, version, false);
  1581. }
  1582. }
  1583. //Complete Installation
  1584. Upgrade.Upgrade.UpgradeApplication();
  1585. if (!string.IsNullOrEmpty(strErrorMessage))
  1586. {
  1587. result = "ERROR: " + strErrorMessage;
  1588. }
  1589. }
  1590. return result;
  1591. }
  1592. else
  1593. {
  1594. return "Done";
  1595. }
  1596. }
  1597. /// -----------------------------------------------------------------------------
  1598. /// <summary>
  1599. /// Runs when the Selected Database is changed
  1600. /// </summary>
  1601. /// <remarks>
  1602. /// </remarks>
  1603. /// <history>
  1604. /// [cnurse] 02/23/2007 Created
  1605. /// </history>
  1606. /// -----------------------------------------------------------------------------
  1607. protected void rblDatabases_SelectedIndexChanged(object sender, EventArgs e)
  1608. {
  1609. BindConnectionString();
  1610. SetupDatabasePage();
  1611. LocalizePage();
  1612. }
  1613. /// -----------------------------------------------------------------------------
  1614. /// <summary>
  1615. /// Runs when the Active Wizard Step has changed
  1616. /// </summary>
  1617. /// <remarks>
  1618. /// </remarks>
  1619. /// <history>
  1620. /// [cnurse] 02/09/2007 Created
  1621. /// </history>
  1622. /// -----------------------------------------------------------------------------
  1623. protected void wizInstall_ActiveStepChanged(object sender, EventArgs e)
  1624. {
  1625. //Main Title
  1626. Title = LocalizeString("Title") + " - " + LocalizeString("Page" + wizInstall.ActiveStepIndex + ".Title");
  1627. LocalizePage();
  1628. switch (wizInstall.ActiveStepIndex)
  1629. {
  1630. case 1: //Page 1 - File Permissions
  1631. BindPermissions(true);
  1632. break;
  1633. case 2: //Page 2 - Bind database connection form
  1634. BindConnectionString();
  1635. break;
  1636. case 4: //Page 4 - Modules
  1637. if (installTypeRadioButton.SelectedValue == "Typical")
  1638. {
  1639. BindModules();
  1640. if (InstallModules())
  1641. {
  1642. //Skip Modules Page
  1643. wizInstall.ActiveStepIndex = 5;
  1644. }
  1645. }
  1646. break;
  1647. case 5: //Page 5 - Skins/Conatiners
  1648. if (installTypeRadioButton.SelectedValue == "Typical")
  1649. {
  1650. BindSkins();
  1651. if (InstallSkins())
  1652. {
  1653. //Skip Skins Page
  1654. wizInstall.ActiveStepIndex = 6;
  1655. }
  1656. }
  1657. break;
  1658. case 6: //Page 6 - Languages
  1659. if (installTypeRadioButton.SelectedValue == "Typical")
  1660. {
  1661. BindLanguages();
  1662. if (InstallLanguages())
  1663. {
  1664. //Skip Languages Page
  1665. wizInstall.ActiveStepIndex = 7;
  1666. }
  1667. }
  1668. break;
  1669. case 7: //Page 7 - Auth Systems
  1670. if (installTypeRadioButton.SelectedValue == "Typical")
  1671. {
  1672. BindAuthSystems();
  1673. if (InstallAuthSystems())
  1674. {
  1675. //Skip Auth Systems Page
  1676. wizInstall.ActiveStepIndex = 8;
  1677. }
  1678. }
  1679. break;
  1680. case 8: //Page 8 - Providers
  1681. if (installTypeRadioButton.SelectedValue == "Typical")
  1682. {
  1683. BindProviders();
  1684. if (InstallProviders())
  1685. {
  1686. //Skip Providers Page
  1687. wizInstall.ActiveStepIndex = 9;
  1688. }
  1689. }
  1690. break;
  1691. case 9: //Page 9 - SMTP Settings
  1692. if (installTypeRadioButton.SelectedValue == "Full")
  1693. {
  1694. SMTPSettingsPanel.Visible = true;
  1695. }
  1696. break;
  1697. }
  1698. SetupPage();
  1699. }
  1700. /// -----------------------------------------------------------------------------
  1701. /// <summary>
  1702. /// Runs when the Wizard's Next button is clicked
  1703. /// </summary>
  1704. /// <remarks>
  1705. /// </remarks>
  1706. /// <history>
  1707. /// [cnurse] 02/20/2007 Created
  1708. /// </history>
  1709. /// -----------------------------------------------------------------------------
  1710. protected void wizInstall_NextButtonClick(object sender, WizardNavigationEventArgs e)
  1711. {
  1712. switch (e.CurrentStepIndex)
  1713. {
  1714. case 0:
  1715. if (installTypeRadioButton.SelectedValue == "Auto")
  1716. {
  1717. Response.Redirect("~/Install/Install.aspx?mode=install");
  1718. }
  1719. break;
  1720. case 1: //Page 1 - File Permissions
  1721. BindPermissions(true);
  1722. e.Cancel = !PermissionsValid;
  1723. break;
  1724. case 2: //Page 2 - Database Configuration
  1725. bool canConnect = TestDatabaseConnection();
  1726. if (canConnect)
  1727. {
  1728. //Update Connection String
  1729. Config.UpdateConnectionString(_connectionString);
  1730. string dbOwner;
  1731. if (chkOwner.Checked)
  1732. {
  1733. dbOwner = "dbo";
  1734. }
  1735. else
  1736. {
  1737. dbOwner = (string.IsNullOrEmpty(GetUpgradeConnectionStringUserID()))
  1738. ? txtUserId.Text
  1739. : GetUpgradeConnectionStringUserID();
  1740. }
  1741. if (rblDatabases.SelectedValue == "Oracle")
  1742. {
  1743. Config.UpdateDataProvider("OracleDataProvider", "", txtqualifier.Text);
  1744. }
  1745. else
  1746. {
  1747. Config.UpdateDataProvider("SqlDataProvider", dbOwner, txtqualifier.Text);
  1748. }
  1749. //Get Base DatabaseVersion
  1750. GetBaseDatabaseVersion();
  1751. }
  1752. else
  1753. {
  1754. e.Cancel = true;
  1755. }
  1756. break;
  1757. case 3: //Page 3 - Database Installation
  1758. e.Cancel = !TestDataBaseInstalled();
  1759. break;
  1760. case 4: //Page 4 - Modules
  1761. e.Cancel = !InstallModules();
  1762. break;
  1763. case 5: //Page 5 - Skins/Containers
  1764. e.Cancel = !InstallSkins();
  1765. break;
  1766. case 6: //Page 6 - Languages
  1767. e.Cancel = !InstallLanguages();
  1768. break;
  1769. case 7: //Page 7 - Auth Systems
  1770. e.Cancel = !InstallAuthSystems();
  1771. break;
  1772. case 8: //Page 8 - Providers
  1773. e.Cancel = !InstallProviders();
  1774. break;
  1775. case 9: //Page 9 - Admin/Host User
  1776. //Check if SMTP needs to be tested
  1777. if (!String.IsNullOrEmpty(txtSMTPServer.Text))
  1778. {
  1779. if (!TestSMTPSettings())
  1780. {
  1781. e.Cancel = true;
  1782. return;
  1783. }
  1784. }
  1785. if (!InstallHost())
  1786. {
  1787. e.Cancel = true;
  1788. return;
  1789. }
  1790. e.Cancel = !InstallPortal();
  1791. break;
  1792. }
  1793. }
  1794. // ReSharper restore InconsistentNaming
  1795. #endregion
  1796. }
  1797. }