PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Domains.ascx.cs

#
C# | 259 lines | 186 code | 39 blank | 34 comment | 42 complexity | 7338c58ad3fd9916ce0eb0edf271482d MD5 | raw file
Possible License(s): BSD-3-Clause, Unlicense, MPL-2.0-no-copyleft-exception, LGPL-2.0
  1. // Copyright (c) 2015, Outercurve Foundation.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without modification,
  5. // are permitted provided that the following conditions are met:
  6. //
  7. // - Redistributions of source code must retain the above copyright notice, this
  8. // list of conditions and the following disclaimer.
  9. //
  10. // - Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. //
  14. // - Neither the name of the Outercurve Foundation nor the names of its
  15. // contributors may be used to endorse or promote products derived from this
  16. // software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  22. // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  25. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. using System;
  29. using System.Data;
  30. using System.Configuration;
  31. using System.Collections;
  32. using System.Web;
  33. using System.Web.Security;
  34. using System.Web.UI;
  35. using System.Web.UI.WebControls;
  36. using System.Web.UI.WebControls.WebParts;
  37. using System.Web.UI.HtmlControls;
  38. using System.Linq;
  39. using WebsitePanel.EnterpriseServer;
  40. using System.Collections.Generic;
  41. using System.Text;
  42. namespace WebsitePanel.Portal
  43. {
  44. public partial class Domains : WebsitePanelModuleBase
  45. {
  46. public Dictionary<int, string> dnsRecords;
  47. protected void Page_Load(object sender, EventArgs e)
  48. {
  49. ClientScriptManager cs = Page.ClientScript;
  50. cs.RegisterClientScriptInclude("jquery", ResolveUrl("~/JavaScript/jquery-1.4.4.min.js"));
  51. dnsRecords = new Dictionary<int, string>();
  52. gvDomains.PageSize = UsersHelper.GetDisplayItemsPerPage();
  53. // visibility
  54. chkRecursive.Visible = (PanelSecurity.SelectedUser.Role != UserRole.User);
  55. gvDomains.Columns[5].Visible = gvDomains.Columns[6].Visible =
  56. (PanelSecurity.SelectedUser.Role != UserRole.User) && chkRecursive.Checked;
  57. gvDomains.Columns[7].Visible = (PanelSecurity.SelectedUser.Role == UserRole.Administrator);
  58. gvDomains.Columns[8].Visible = (PanelSecurity.EffectiveUser.Role == UserRole.Administrator);
  59. if (!IsPostBack)
  60. {
  61. // toggle controls
  62. btnAddDomain.Enabled = PackagesHelper.CheckGroupQuotaEnabled(PanelSecurity.PackageId, ResourceGroups.Os, Quotas.OS_DOMAINS)
  63. || PackagesHelper.CheckGroupQuotaEnabled(PanelSecurity.PackageId, ResourceGroups.Os, Quotas.OS_SUBDOMAINS)
  64. || PackagesHelper.CheckGroupQuotaEnabled(PanelSecurity.PackageId, ResourceGroups.Os, Quotas.OS_DOMAINPOINTERS);
  65. searchBox.AddCriteria("DomainName", GetLocalizedString("SearchField.DomainName"));
  66. if ((PanelSecurity.SelectedUser.Role != UserRole.User) && chkRecursive.Checked)
  67. {
  68. searchBox.AddCriteria("Username", GetLocalizedString("SearchField.Username"));
  69. searchBox.AddCriteria("FullName", GetLocalizedString("SearchField.FullName"));
  70. searchBox.AddCriteria("Email", GetLocalizedString("SearchField.Email"));
  71. }
  72. }
  73. searchBox.AjaxData = this.GetSearchBoxAjaxData();
  74. }
  75. public string GetItemEditUrl(object packageId, object itemId)
  76. {
  77. return EditUrl("DomainID", itemId.ToString(), "edit_item",
  78. PortalUtils.SPACE_ID_PARAM + "=" + packageId.ToString());
  79. }
  80. public string GetUserHomePageUrl(int userId)
  81. {
  82. return PortalUtils.GetUserHomePageUrl(userId);
  83. }
  84. public string GetSpaceHomePageUrl(int spaceId)
  85. {
  86. return NavigateURL(PortalUtils.SPACE_ID_PARAM, spaceId.ToString());
  87. }
  88. public string GetItemsPageUrl(string parameterName, string parameterValue)
  89. {
  90. return NavigateURL(PortalUtils.SPACE_ID_PARAM, PanelSecurity.PackageId.ToString(),
  91. parameterName + "=" + parameterValue);
  92. }
  93. public string GetDomainTypeName(bool isSubDomain, bool isInstantAlias, bool isDomainPointer)
  94. {
  95. if(isDomainPointer)
  96. return GetLocalizedString("DomainType.DomainPointer");
  97. else if (isSubDomain)
  98. return GetLocalizedString("DomainType.SubDomain");
  99. else
  100. return GetLocalizedString("DomainType.Domain");
  101. }
  102. public string GetDomainExpirationDate(object expirationDateObject, object LastUpdateDateObject)
  103. {
  104. var expirationDate = expirationDateObject as DateTime?;
  105. var lastUpdateDate = LastUpdateDateObject as DateTime?;
  106. if (expirationDate != null && expirationDate < DateTime.Now)
  107. {
  108. return GetLocalizedString("DomainExpirationDate.Expired");
  109. }
  110. else if(expirationDate != null)
  111. {
  112. return expirationDate.Value.ToShortDateString();
  113. }
  114. else if (lastUpdateDate == null)
  115. {
  116. return GetLocalizedString("DomainExpirationDate.NotChecked");
  117. }
  118. else
  119. {
  120. return GetLocalizedString("DomainExpirationDate.NotExist");
  121. }
  122. }
  123. public bool ShowDomainDnsInfo(object expirationDateObject, object LastUpdateDateObject, bool isTopLevelDomain)
  124. {
  125. var expirationDate = expirationDateObject as DateTime?;
  126. var lastUpdateDate = LastUpdateDateObject as DateTime?;
  127. if (!isTopLevelDomain)
  128. {
  129. return false;
  130. }
  131. else if (expirationDate != null && expirationDate < DateTime.Now)
  132. {
  133. return false;
  134. }
  135. else if(expirationDate != null)
  136. {
  137. return true;
  138. }
  139. else if (lastUpdateDate == null)
  140. {
  141. return false;
  142. }
  143. else
  144. {
  145. return false;
  146. }
  147. }
  148. public string GetDomainDnsRecords(int domainId)
  149. {
  150. if(dnsRecords.ContainsKey(domainId))
  151. {
  152. return dnsRecords[domainId];
  153. }
  154. var records = ES.Services.Servers.GetDomainDnsRecords(domainId);
  155. if (!records.Any())
  156. {
  157. dnsRecords.Add(domainId, string.Empty);
  158. return string.Empty;
  159. }
  160. var header = GetLocalizedString("DomainLookup.TooltipHeader");
  161. var tooltipLines = new List<string>();
  162. tooltipLines.Add(header);
  163. tooltipLines.Add(" ");
  164. tooltipLines.AddRange( records.Select(x=>string.Format("{0}: {1}", x.RecordType, x.Value)));
  165. dnsRecords.Add(domainId, string.Join("\r\n", tooltipLines));
  166. return dnsRecords[domainId];
  167. }
  168. public string GetDomainTooltip(int domainId, string registrar)
  169. {
  170. var dnsString = GetDomainDnsRecords(domainId);
  171. var tooltipLines = new List<string>();
  172. if (!string.IsNullOrEmpty(registrar))
  173. {
  174. var header = GetLocalizedString("DomainLookup.TooltipHeader.Registrar");
  175. tooltipLines.Add(header + " " + registrar);
  176. tooltipLines.Add("\r\n");
  177. }
  178. return string.Join("\r\n", tooltipLines) + dnsString;
  179. }
  180. protected void odsDomainsPaged_Selected(object sender, ObjectDataSourceStatusEventArgs e)
  181. {
  182. if (e.Exception != null)
  183. {
  184. ProcessException(e.Exception);
  185. //this.DisableControls = true;
  186. e.ExceptionHandled = true;
  187. }
  188. }
  189. protected void btnAddDomain_Click(object sender, EventArgs e)
  190. {
  191. Response.Redirect(EditUrl(PortalUtils.SPACE_ID_PARAM, PanelSecurity.PackageId.ToString(), "add_domain"));
  192. }
  193. protected void gvDomains_RowCommand(object sender, GridViewCommandEventArgs e)
  194. {
  195. if (e.CommandName == "Detach")
  196. {
  197. // remove item from meta base
  198. int domainId = Utils.ParseInt(e.CommandArgument.ToString(), 0);
  199. int result = ES.Services.Servers.DetachDomain(domainId);
  200. if (result < 0)
  201. {
  202. ShowResultMessage(result);
  203. // return;
  204. }
  205. // refresh the list
  206. //gvDomains.DataBind();
  207. }
  208. }
  209. public string GetSearchBoxAjaxData()
  210. {
  211. StringBuilder res = new StringBuilder();
  212. res.Append("PagedStored: 'Domains'");
  213. res.Append(", RedirectUrl: '" + GetItemEditUrl(Request["SpaceID"] ?? "-1", "{0}").Substring(2) + "'");
  214. res.Append(", PackageID: " + (String.IsNullOrEmpty(Request["SpaceID"]) ? "-1" : Request["SpaceID"]));
  215. res.Append(", ServerID: " + (String.IsNullOrEmpty(Request["ServerID"]) ? "0" : Request["ServerID"]));
  216. res.Append(", Recursive: ($('#" + chkRecursive.ClientID + "').val() == 'on')");
  217. return res.ToString();
  218. }
  219. }
  220. }