Exemplo n.º 1
0
        public void ActionSendMail(EmailEntity emailEntity)
        {
            // Lay danh sach CVE
            ModCVEEntity cve = ModCVEService.Instance.CreateQuery().Where(o => o.ID == emailEntity.RecordID).ToSingle();

            // Lay template
            ModEmailTemplateEntity emailTemp = ModEmailTemplateService.Instance.CreateQuery().Where(o => o.Activity == true && o.Code == "Type1").ToSingle();

            // Lay he thong thong tin theo CVE tuong ung
            string s     = cve.VulnerabilityType;
            var    query = ModHeThongThongTinService.Instance.CreateQuery()
                           .Where(o => o.Activity == true)
                           .Where(!string.IsNullOrEmpty(s), o => o.Name.Contains(s));
            List <ModHeThongThongTinEntity> lstHttt = query.ToList();

            string emailTos = "";

            if (lstHttt != null)
            {
                string dauMoiIds = string.Join(",", lstHttt.Select(o => o.DauMoiUCSCID).ToArray());
                string donDkIds  = string.Join(",", lstHttt.Select(o => o.DonDangKyUCSCID).ToArray());

                // Lay dau moi UCSC
                List <ModDauMoiUCSCEntity> lstDauMoi = ModDauMoiUCSCService.Instance.CreateQuery()
                                                       .Where(o => o.Activity == true)
                                                       .WhereIn(dauMoiIds != "", o => o.ID, dauMoiIds)
                                                       .ToList();
                emailTos = string.Join(";", lstDauMoi.Select(o => o.Email).ToArray());

                // Lay don DK
                List <ModDonDangKyUCSCEntity> lstDangKy = ModDonDangKyUCSCService.Instance.CreateQuery()
                                                          .Where(o => o.Activity == true)
                                                          .WhereIn(donDkIds != "", o => o.ID, donDkIds)
                                                          .ToList();
                emailTos += ";" + string.Join(";", lstDangKy.Select(o => o.ToChuc_Email).ToArray());
                emailTos.Replace(";;", ";").Replace(";;", ";").Replace(";;", ";").Trim(';');
            }

            if (emailTemp != null)
            {
                if (emailTos != "")
                {
                    emailEntity.To = emailTos;
                }
                emailEntity.Cc      = "*****@*****.**";
                emailEntity.Subject = string.Format(emailTemp.Subject, "");
                emailEntity.Body    = cve.VulnerabilityType;
            }

            ViewBag.Data = emailEntity;
        }
Exemplo n.º 2
0
        public void ActionSendMailExcute(EmailEntity emailEntity)
        {
            ViewBag.Data = emailEntity;

            CPViewPage.Message.MessageType = Message.MessageTypeEnum.Error;

            if (string.IsNullOrEmpty(emailEntity.To))
            {
                CPViewPage.Message.ListMessage.Add("Bạn chưa nhập Email tiếp nhận.");
            }
            else
            {
                var toArr = emailEntity.To.Split(',');
                foreach (var i in toArr)
                {
                    if (Utils.GetEmailAddress(i) == string.Empty)
                    {
                        CPViewPage.Message.ListMessage.Add("Định dạng Email tiếp nhận không đúng.");
                    }
                }
            }

            if (!string.IsNullOrEmpty(emailEntity.Cc))
            {
                var ccArr = emailEntity.Cc.Split(',');
                foreach (var i in ccArr)
                {
                    if (Utils.GetEmailAddress(i) == string.Empty)
                    {
                        CPViewPage.Message.ListMessage.Add("Định dạng Email Cc không đúng.");
                    }
                }
            }

            if (string.IsNullOrEmpty(emailEntity.Subject))
            {
                CPViewPage.Message.ListMessage.Add("Bạn chưa nhập Tiêu đề.");
            }

            if (string.IsNullOrEmpty(emailEntity.Body))
            {
                CPViewPage.Message.ListMessage.Add("Bạn chưa nhập Nội dung.");
            }

            if (CPViewPage.Message.ListMessage.Count == 0)
            {
                // Goi ham send mail
                string sendResult = Mail.SendMailUseSMTP(emailEntity.To, emailEntity.Cc, emailEntity.Subject, emailEntity.Body, emailEntity.Attach);

                if (!string.IsNullOrEmpty(sendResult))
                {
                    CPViewPage.Message.ListMessage.Add("Gửi mail lỗi. Hãy kiểm tra lại việc cấu hình email của bạn.");
                }
                else
                {
                    CPViewPage.SetMessage("Gửi mail thành công.");

                    // Thuc hien tang so lan gui mail them 1
                    var CVE = ModCVEService.Instance.CreateQuery().Where(o => o.ID == emailEntity.RecordID).ToSingle();
                    CVE.EmailNo++;
                    ModCVEService.Instance.Save(CVE);
                }
            }
        }
Exemplo n.º 3
0
        //public void ExportToPDF(ModIncidentModel model)
        //{
        //    RenderView("Index");

        //    //lấy danh sách thuật ngữ
        //    var listEntity = ModIncidentService.Instance.CreateQuery()
        //                //.Where(o => o.Activity == true)
        //                .ToList();

        //    //khai báo tập hợp bản ghi excel
        //    List<List<object>> list = new List<List<object>>();
        //    //khai báo 1 dòng excel
        //    List<object> _list = null;
        //    string cityname = "";
        //    for (int i = 0; listEntity != null && listEntity.Count > 0 && i < listEntity.Count; i++)
        //    {
        //        _list = new List<object>();
        //        //add 1 dòng excel
        //        // _list.Add(i + 1);
        //        _list.Add(listEntity[i].Name);
        //        _list.Add(cityname);
        //        _list.Add(listEntity[i].Published);
        //        list.Add(_list);
        //    }

        //    //ghi exel
        //    string temp_file = CPViewPage.Server.MapPath("~/Data/upload/files/Excel/DanhSachSuCo_" +
        //    string.Format("{0:dd_MM_yyyy}", DateTime.Now) + ".xls");
        //    string filePath = CPViewPage.Server.MapPath("~/TTPortal/Templates/DanhSachSuCo.xlsx");



        //    CPViewPage.Response.ContentType = "application/pdf";
        //    CPViewPage.Response.AddHeader("content-disposition", "attachment;filename=DataTable.pdf");
        //    CPViewPage.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        //    StringWriter sw = new StringWriter();
        //    HtmlTextWriter hw = new HtmlTextWriter(sw);
        //    GridView1.RenderControl(hw);
        //    StringReader sr = new StringReader(sw.ToString());
        //    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        //    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        //    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        //    pdfDoc.Open();
        //    htmlparser.Parse(sr);
        //    pdfDoc.Close();
        //    CPViewPage.Response.Write(pdfDoc);
        //    CPViewPage.Response.End();
        //}

        public void ActionSendMail(EmailEntity emailEntity)
        {
            // Lay danh sach su co
            ModIncidentEntity        suCoParent = ModIncidentService.Instance.CreateQuery().Where(o => o.ID == emailEntity.RecordID).ToSingle();
            List <ModIncidentEntity> suCos = null;
            WebMenuEntity            menuIncident = null;
            string sSuCo = string.Empty, isp = string.Empty, ip = string.Empty;
            string s2 = string.Empty, s3 = string.Empty, s4 = string.Empty, sName = string.Empty;

            //{2}: (giả mạo (phishing), nhiễm mã độc  (malware), (thay đổi giao diện) Deface )
            //{3}: , và các cố {2}
            // {4}: {2} + {3}
            if (suCoParent != null)
            {
                suCos  = ModIncidentService.Instance.CreateQuery().Where(o => o.Resolve == false && o.ParentID == suCoParent.ID).ToList();
                sSuCo += "<b><span>" + suCoParent.Path + "</span></b>";
                isp    = suCoParent.ISP;
                ip     = suCoParent.IP;
            }
            if (suCos != null && suCos.Count > 0)
            {
                int countSuCo = suCos.Count;
                for (int i = 0; i < countSuCo; i++)
                {
                    menuIncident = WebMenuService.Instance.CreateQuery().Where(o => o.Activity == true && o.Type == "Incident" && o.ID == suCos[i].MenuID).ToSingle();
                    if (menuIncident != null)
                    {
                        sName = menuIncident.Code == "Phishing" ? "giả mạo (Phishing)" : menuIncident.Code == "Malware" ? "nhiễm mã độc(Malware)" : "thay đổi giao diện (Deface)";
                        if (i == 0)
                        {
                            s2 = sName;
                        }
                        else
                        {
                            s3 += sName;
                            if (i < countSuCo - 1)
                            {
                                s3 += ", ";
                            }
                        }
                    }
                    sSuCo += "<br />&nbsp;&nbsp;&nbsp;&nbsp;" + suCos[i].Path + "<br />";
                }
            }
            sSuCo += ip;

            // Lay template
            ModEmailTemplateEntity emailTemp = ModEmailTemplateService.Instance.CreateQuery().Where(o => o.Activity == true && o.Code == "Type1").ToSingle();

            // Lay email gui di theo ISP
            ModISPEntity ispEntity = ModISPService.Instance.CreateQuery().Where(o => o.Activity == true && o.Name == isp).ToSingle();

            if (emailTemp != null)
            {
                if (ispEntity != null)
                {
                    emailEntity.To = ispEntity.Email;
                }
                emailEntity.Cc      = "*****@*****.**";
                emailEntity.Subject = string.Format(emailTemp.Subject, isp);
                emailEntity.Body    = string.Format(emailTemp.Content, isp, sSuCo, s2, (!string.IsNullOrEmpty(s3) ? ", và các sự cố " + s3 : ""), s2 + (!string.IsNullOrEmpty(s3) ? ", " + s3 : ""));
            }

            ViewBag.Data = emailEntity;
        }