public Task CertView([FromForm] string content) { CertInfo result = HttpsHelper.GetFirstCertInfo(content); if (!result.Success) { return(this.ShowError(result.Message)); } return(this.GetResult(result.ToString())); }
/// <summary> /// 添加SSL证书 /// </summary> /// <param name="cert"></param> /// <returns></returns> public bool SaveCertInfo(SiteDomainCert cert) { if (cert.SiteID == 0) { return(this.FaildMessage("没有指定站点")); } if (string.IsNullOrEmpty(cert.PEM)) { return(this.FaildMessage("未选择证书")); } if (string.IsNullOrEmpty(cert.KEY)) { return(this.FaildMessage("未选择密钥")); } CertInfo info = HttpsHelper.GetFirstCertInfo(cert.PEM); if (!info.Success) { return(this.FaildMessage(info.Message)); } cert.Name = info.Message; cert.Domain = string.Join(",", info.Domain); cert.Expire = info.ExpireAt; cert.CreateAt = DateTime.Now; if (this.ReadDB.Exists <SiteDomainCert>(t => t.SiteID == cert.SiteID && t.ID != cert.ID && t.Name == cert.Name)) { return(this.FaildMessage("已存在同名的证书")); } bool success = false; using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted)) { if (cert.ID == 0) { success = cert.Add(db); } else { success = cert.Update(db) == 1; } db.Commit(); } return(success && AccountInfo.Log(LogType.Site, string.Format("设定域名证书 {0}", cert.Name))); }