コード例 #1
0
        public Task CertInfo([FromForm] int id, [FromForm] int siteId)
        {
            SiteDomainCert cert = CertAgent.Instance().GetCertInfo(id) ?? new SiteDomainCert()
            {
                SiteID = siteId
            };

            return(this.GetResult(cert));
        }
コード例 #2
0
        /// <summary>
        /// 删除SSL证书
        /// </summary>
        /// <param name="certId"></param>
        /// <returns></returns>
        public bool DeleteCertInfo(int certId)
        {
            SiteDomainCert cert = this.GetCertInfo(certId);

            if (cert == null)
            {
                return(this.FaildMessage("编号错误"));
            }
            return(cert.Delete(this.WriteDB) &&
                   AccountInfo.Log(LogType.Site, string.Format("删除站点{0} 证书{1}", cert.SiteID, cert.Name)));
        }
コード例 #3
0
        public Task SaveCert([FromForm] int id, [FromForm] int siteId, [FromForm] string pem, [FromForm] string key)
        {
            SiteDomainCert cert = new SiteDomainCert()
            {
                ID     = id,
                SiteID = siteId,
                KEY    = key,
                PEM    = pem
            };

            return(this.GetResult(CertAgent.Instance().SaveCertInfo(cert)));
        }
コード例 #4
0
        /// <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)));
        }