public static SelectedValueStruct ParseSelectedValue(string Domain) { SelectedValueStruct sds = new SelectedValueStruct(); if (Domain.Trim() != string.Empty) { string[] domains = Domain.Split(new Char[] { '_' }, 2); if (domains.Length > 1) { sds.Type = domains[0]; sds.Name = domains[1]; } } return(sds); }
protected void InitDomain() { string[] dName = new string[1]; string domainName = ""; if (_isUpdate) { _actionDomain = "Edit Domain"; intIncomingMailProtocol.Attributes["class"] = "wm_hide"; ButtonSave.Visible = false; trForHr.Visible = false; textDomainName.Attributes.Add("class", "wm_hide"); string uid = HttpUtility.UrlDecode(this.Request.QueryString["uid"].ToString()); SelectedValueStruct sds = AdminPanelUtils.ParseSelectedValue(uid); hidCustomDomain.Value = "0"; dName[0] = sds.Name; string domains; XMLayer xmLayer = XMServer.CreateXMLayer(); switch (sds.Type) { case AdminPanelConstants.UserType.xm: case AdminPanelConstants.UserType.xma: try { xmLayer.Login(); domains = xmLayer.ListDomains(dName); using (StringReader sr = new StringReader(domains)) { string line = string.Empty; while ((line = sr.ReadLine()) != null) { line = line.Trim(); if (line == ".") { break; } domainName = line.Trim(new char[] { '"' }); } } textDomainName.Value = domainName; } catch (Exception error) { Log.WriteException(error); AdminPanelUtils.SetPageErrorMessage(this.Page, error.Message); } finally { xmLayer.Logout(); } break; case AdminPanelConstants.UserType.xmc: _domainType = "vir"; try { xmLayer.Login(); domainName = dName[0]; hidCustomDomain.Value = "1"; ButtonSave.Visible = true; trForHr.Visible = true; string DomainStringArray = XMDomain.GetCustomDomainTab(sds.Name)[0]; using (StringReader sr = new StringReader(DomainStringArray)) { string[] data; string line; // RedirectionsListDDL.Items.Clear(); LRedirectionsListDDL.Items.Clear(); while ((line = sr.ReadLine()) != null) { line = line.Trim(); data = XMDomain.extractCustomDomainData(line); int i; switch (data[0]) { case "mailbox": break; /* * case "redirect": * for (i = 1; i < data.Length; i++) * RedirectionsListDDL.Items.Add(data[i]); * break; */ case "lredirect": for (i = 1; i < data.Length; i++) { LRedirectionsListDDL.Items.Add(data[i]); } break; } } AdvancedID.Text = XMDomain.GetCustomDomainTab(domainName)[1]; textDomainName.Value = domainName; } } catch (Exception error) { Log.WriteException(error); AdminPanelUtils.SetPageErrorMessage(this.Page, error.Message); } finally { xmLayer.Logout(); } break; case AdminPanelConstants.UserType.wm: //Webmail Domains _domainType = "rem"; ButtonSave.Visible = true; trForHr.Visible = true; try { Domain dom = Domain.LoadFromDb(sds.Name.Trim()); textDomainName.Value = dom.Name; domainName = dom.Name; txtIncomingMail.Value = dom.MailIncomingHost; intIncomingMailPort.Value = dom.MailIncomingPort.ToString(); txtOutgoingMail.Value = dom.MailOutgoingHost; intOutgoingMailPort.Value = dom.MailOutgoingPort.ToString(); intReqSmtpAuthentication.Checked = dom.MailOutgoingAuthentication; hidWebMailDomainID.Value = dom.ID.ToString(); switch (dom.MailIncomingProtocol) { case IncomingMailProtocol.Pop3: intIncomingMailProtocol.SelectedIndex = 0; break; case IncomingMailProtocol.Imap4: intIncomingMailProtocol.SelectedIndex = 1; break; default: intIncomingMailProtocol.SelectedIndex = 0; break; } } catch (Exception error) { Log.WriteException(error); AdminPanelUtils.SaveState("SessPageErrorMessage", WebMail.Constants.mailAdmUpdateAccountUnsuccess, Page.Session); } break; } UID = HttpUtility.UrlEncode(sds.Type + "_" + domainName); if (AdminPanelUtils.IsSuperAdmin(Page.Session, (Page as DefaultPage).Settings)) { Domain dom = new Domain(); if (UID.Length > 0) { try { SelectedValueStruct sus = AdminPanelUtils.ParseSelectedValue(uid); if (sus.Type != AdminPanelConstants.UserType.xm) { try { dom = Domain.LoadFromDb(sus.Name); } catch { } } } catch (Exception ex) { Log.WriteException(ex); AdminPanelUtils.SetPageErrorMessage(this.Page, (ex.InnerException != null ? ex.InnerException.Message : ex.Message)); } } if (dom != null) { domain_filter = dom.ID.ToString(); } } litDomainName.Text = @"<span style=""font-size: large;"">" + domainName + "</span>"; switch (_domainType) { case "vir": litDomainDescription.Text = "Defines rules for forwarding mail from this domain to other addresses."; break; case "rem": litDomainDescription.Text = "Contains users hosted by other mail services (e.g. gmx.com)."; break; default: litDomainDescription.Text = "Contains users hosted by this server."; break; } } else { _actionDomain = "Create Domain"; divDomainName.Attributes["class"] = "wm_hide"; intIncomingMailPort.Value = "110"; intOutgoingMailPort.Value = "25"; switch (_domainType) { case "vir": litDomainDescriptionView.Text = "Defines rules for forwarding mail from this domain to other addresses."; break; case "rem": litDomainDescriptionView.Text = "Contains users hosted by other mail services (e.g. gmx.com)."; break; default: litDomainDescriptionView.Text = "Contains users hosted by this server."; break; } } switch (_domainType) { case "vir": tr_custom_options.Attributes["class"] = ""; break; case "rem": tr_webmail_options.Attributes["class"] = ""; break; default: tr_custom_options.Attributes["class"] = "wm_hide"; tr_webmail_options.Attributes["class"] = "wm_hide"; break; } if (!AdminPanelUtils.IsSuperAdmin(Page.Session, (Page as DefaultPage).Settings)) { tr_see_webmail.Attributes["class"] = "wm_hide"; } }
protected void Page_Load(object sender, EventArgs e) { (Page as DefaultPage).Body = " onresize=\"ResizeElements('all');\""; AdminPanelUtils.ShowReportAndReportMessages(Page); bool result = CheckDB(); if (result) { string mode = (!string.IsNullOrEmpty(Request.QueryString["mode"]) ? Request.QueryString["mode"] : "domains"); domains_management domainsControl = (domains_management)LoadControl(@"domains.ascx"); if (domainsControl != null) { if (!string.IsNullOrEmpty(Request.QueryString["asc"])) { domainsControl.Asc = (string.Compare(Request.QueryString["asc"], "true", true, CultureInfo.InvariantCulture) == 0) ? true : false; } if (!string.IsNullOrEmpty(Request.QueryString["order"])) { domainsControl.OrderBy = Request.QueryString["order"]; } ContentPlaceHolder.Controls.Add(domainsControl); } try { switch (mode) { case "new": if (AdminPanelUtils.IsSuperAdmin(Page.Session, (Page as DefaultPage).Settings)) { Control ctrl = LoadControl(@"domain-edit.ascx"); if (ctrl != null) { domainsControl.FindControl("PlaceHolderDomain").Controls.Add(ctrl); } } break; case "edit": { if ((!string.IsNullOrEmpty(Request.QueryString["name"])) || (!string.IsNullOrEmpty(Request.QueryString["uid"]))) { Control ctrl = LoadControl(@"domain-edit.ascx"); if (ctrl != null) { domainsControl.FindControl("PlaceHolderDomain").Controls.Add(ctrl); } } } break; case "close_search": { AdminPanelUtils.SaveState("wm_adm_dm_condition", null, Page.Session); Response.Redirect(string.Format(@"default.aspx?mode=domains"), false); } break; } if (Page.IsPostBack) { AdminPanelUtils.SaveState("Page", Request[domainsControl.FindControl("HFPageInfo").UniqueID].ToString(), Page.Session); string action = Request[domainsControl.FindControl("HFAction").UniqueID].ToString(); string value = Request[domainsControl.FindControl("HFValue").UniqueID].ToString(); switch (action) { case "sort": if (value != "") { bool sortOrder = true; AdminPanelUtils.SaveState("wm_adm_dm_order", value, Page.Session); if (Session["wm_adm_dmAsc"] != null) { sortOrder = bool.Parse(Session["wm_adm_dmAsc"].ToString()); } Session["wm_adm_dmAsc"] = !sortOrder; } Response.Redirect(Request.RawUrl, false); break; case "search": AdminPanelUtils.SaveState("wm_adm_dm_condition", value, Page.Session); Response.Redirect(string.Format(@"default.aspx?mode=domains"), false); break; case "delete": if (AdminPanelUtils.IsSuperAdmin(Page.Session, (Page as DefaultPage).Settings)) { try { string[] values = value.Split(','); foreach (string val in values) { SelectedValueStruct sds = AdminPanelUtils.ParseSelectedValue(HttpUtility.UrlDecode(val)); DeleteDomain(sds.Name, sds.Type); if (AdminPanelUtils.LoadState("selectedDomain", Page.Session) != null && AdminPanelUtils.LoadState("selectedDomain", Page.Session).ToString() == val) { AdminPanelUtils.SaveState("selectedDomain", null, Page.Session); } } AdminPanelUtils.SaveState("SessPageReportMessage", WebMail.Constants.mailAdmUpdateAccountSuccess, Page.Session); } catch { AdminPanelUtils.SaveState("SessPageErrorMessage", WebMail.Constants.mailAdmUpdateAccountUnsuccess, Page.Session); } Response.Redirect(string.Format(@"default.aspx?mode=domains"), false); } break; } } } catch (Exception ex) { Log.WriteException(ex); AdminPanelUtils.SetPageErrorMessage(this.Page, (ex.InnerException != null ? ex.InnerException.Message : ex.Message)); } if (AdminPanelUtils.LoadState("Page", Page.Session) != null) { domainsControl.PageNumber = Int32.Parse(AdminPanelUtils.LoadState("Page", Page.Session).ToString()); } } else { AdminPanelUtils.SetPageErrorMessage(this.Page, "<b>Database is not configured</b>. <br />Before creating domains and users, you need to configure database connection first. <br />Please navigate WebMail / Database Settings and configure database connection there."); } }