Example #1
0
        private string ModifySensitiveMail(HttpContext context)
        {
            string        strJsonResult = string.Empty;
            string        userAccount   = string.Empty;
            ErrorCodeInfo error         = new ErrorCodeInfo();
            Guid          transactionid = Guid.NewGuid();
            string        funname       = "ModifySensitiveMail";

            try
            {
                do
                {
                    string strAccesstoken = context.Request["accessToken"];
                    //判断AccessToken
                    if (string.IsNullOrEmpty(strAccesstoken))
                    {
                        error.Code    = ErrorCode.TokenEmpty;
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(userAccount, funname, context.Request.RawUrl, Convert.ToString(error.Code), false, transactionid);
                        break;
                    }

                    AdminInfo admin = new AdminInfo();
                    if (!TokenManager.ValidateUserToken(transactionid, strAccesstoken, out admin, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(userAccount, funname, context.Request.RawUrl, Convert.ToString(error.Code), false, transactionid);
                        break;
                    }

                    Stream str = context.Request.InputStream;
                    // Find number of bytes in stream.
                    Int32 strLen = Convert.ToInt32(str.Length);
                    // Create a byte array.
                    byte[] strArr = new byte[strLen];
                    // Read stream into byte array.
                    str.Read(strArr, 0, strLen);
                    string body = System.Text.Encoding.UTF8.GetString(strArr);

                    SensitiveMailInfo info = JsonConvert.DeserializeObject <SensitiveMailInfo>(body);

                    SensitiveMailManager manager = new SensitiveMailManager(ClientIP);
                    manager.ModifySensitiveMail(transactionid, admin, info, out strJsonResult);
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Error("SensitiveMail.ashx调用接口ModifySensitiveMail异常", context.Request.RawUrl, ex.ToString(), transactionid);
                LoggerHelper.Info(userAccount, funname, context.Request.RawUrl, Convert.ToString(error.Code), false, transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
            }

            return(strJsonResult);
        }
Example #2
0
        public bool GetSensitiveMailInfo(Guid transactionid, AdminInfo admin, SensitiveMailInfo sensitiveMailInfo, out string strJsonResult)
        {
            bool result = true;

            strJsonResult = string.Empty;
            ErrorCodeInfo error    = new ErrorCodeInfo();
            string        message  = string.Empty;
            string        paramstr = string.Empty;

            paramstr += $"AdminID:{admin.UserID}";
            paramstr += $"ID:{sensitiveMailInfo.ID}";
            string funname = "GetSensitiveMailInfo";

            try
            {
                do
                {
                    SensitiveMailDBProvider Provider = new SensitiveMailDBProvider();
                    if (!Provider.GetSensitiveMailInfo(transactionid, admin, ref sensitiveMailInfo, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }
                    error.Code = ErrorCode.None;
                    string json = JsonConvert.SerializeObject(sensitiveMailInfo);
                    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid);
                    strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info, json);
                    result        = true;
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                LoggerHelper.Error("SensitiveMailManager调用GetSensitiveMailInfo异常", paramstr, ex.ToString(), transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                result        = false;
            }
            return(result);
        }
Example #3
0
        public bool AddUserSensitiveMailQueue(Guid transactionid, SensitiveMailInfo sensitiveMailInfo, out ErrorCodeInfo error)
        {
            bool bResult = true;

            error = new ErrorCodeInfo();
            string message = string.Empty;

            try
            {
                do
                {
                    SensitiveMailDBProvider provider       = new SensitiveMailDBProvider();
                    UserProvider            userProvider   = new UserProvider();
                    DirectoryEntry          ouEntry        = new DirectoryEntry();
                    DirectoryEntry          item           = new DirectoryEntry();
                    CommonProvider          commonProvider = new CommonProvider();

                    for (int j = 0; j < sensitiveMailInfo.Objects.Count; j++)
                    {
                        if (sensitiveMailInfo.Objects[j].ObjectType == NodeType.organizationalUnit)
                        {
                            if (!commonProvider.GetADEntryByGuid(sensitiveMailInfo.Objects[j].ObjectID, out ouEntry, out message))
                            {
                                Log4netHelper.Error($"ID:{sensitiveMailInfo.Objects[j].ObjectID},ObjectName:{sensitiveMailInfo.Objects[j].ObjectName},ObjectType:{sensitiveMailInfo.Objects[j].ObjectType.ToString()},GetADEntryByGuid Error:{message}");
                                continue;
                            }

                            DirectoryEntry de = null;
                            de = new DirectoryEntry(ouEntry.Path);
                            DirectorySearcher deSearch = new DirectorySearcher(de);
                            deSearch.SearchRoot = de;
                            string strFilter = commonProvider.GetSearchType(SearchType.MailUser, string.Empty);
                            deSearch.Filter          = strFilter;
                            deSearch.SearchScope     = SearchScope.Subtree;
                            deSearch.SizeLimit       = 20000;
                            deSearch.ServerTimeLimit = TimeSpan.FromSeconds(600);
                            deSearch.ClientTimeout   = TimeSpan.FromSeconds(600);
                            SearchResultCollection results = deSearch.FindAll();

                            if (results != null && results.Count > 0)
                            {
                                foreach (SearchResult Result in results)
                                {
                                    item = Result.GetDirectoryEntry();
                                    UserInfo user = new UserInfo();
                                    user.UserID         = item.Guid;
                                    user.UserAccount    = item.Properties["userPrincipalName"].Value == null ? "" : Convert.ToString(item.Properties["userPrincipalName"].Value);
                                    user.SAMAccountName = item.Properties["sAMAccountName"].Value == null ? "" : Convert.ToString(item.Properties["sAMAccountName"].Value);
                                    provider.AddUserSensitiveMailQueue(transactionid, sensitiveMailInfo, user, out error);
                                }
                            }
                        }
                        else if (sensitiveMailInfo.Objects[j].ObjectType == NodeType.user)
                        {
                            if (!commonProvider.GetADEntryByGuid(sensitiveMailInfo.Objects[j].ObjectID, out item, out message))
                            {
                                Log4netHelper.Error($"ID:{sensitiveMailInfo.Objects[j].ObjectID},ObjectName:{sensitiveMailInfo.Objects[j].ObjectName},ObjectType:{sensitiveMailInfo.Objects[j].ObjectType.ToString()},GetADEntryByGuid Error:{message}");
                                continue;
                            }
                            UserInfo user = new UserInfo();
                            user.UserID = item.Guid;
                            provider.AddUserSensitiveMailQueue(transactionid, sensitiveMailInfo, user, out error);
                        }
                    }
                } while (false);
            }
            catch (Exception ex)
            {
                Log4netHelper.Error($"RemoveSensitiveMailQueue Exception: {ex.ToString()}");
            }
            return(bResult);
        }
Example #4
0
        public void RemoveSensitiveMailQueue()
        {
            Guid     transactionid = new Guid();
            int      removeSensitiveMailServiceSleepTime = Convert.ToInt32(Common.ConfigHelper.ConfigInstance["removeSensitiveMailServiceSleepTime"]);
            TimeSpan sensitiveMailQueueTimeOut           = TimeSpan.FromSeconds(Convert.ToInt32(Common.ConfigHelper.ConfigInstance["sensitiveMailQueueTimeOut"]));
            int      sensitiveMailQueueCount             = Convert.ToInt32(Common.ConfigHelper.ConfigInstance["sensitiveMailQueueCount"]);

            AdminInfo     adminInfo = new AdminInfo();
            ErrorCodeInfo error     = new ErrorCodeInfo();
            string        message   = string.Empty;

            try
            {
                do
                {
                    string snkey = ConfigHelper.ConfigInstance["SNKey"];
                    //if (ValidatorHelper.CheckSNKey(snkey))
                    //{
                    List <SensitiveMailInfo> sensitiveMails = new List <SensitiveMailInfo>();
                    SensitiveMailDBProvider  provider       = new SensitiveMailDBProvider();
                    UserProvider             userProvider   = new UserProvider();
                    //1.先获取已提交的敏感邮件 2.更新子队列全部执行完成的主数据的状态 3.
                    if (provider.GetSubmitSensitiveMailQueueList(transactionid, out sensitiveMails, out error))
                    {
                        //拆分Ou在子队列总添加用户
                        for (int i = 0; i < sensitiveMails.Count; i++)
                        {
                            SensitiveMailInfo sensitiveMailInfo = sensitiveMails[i];
                            if (!AddUserSensitiveMailQueue(transactionid, sensitiveMailInfo, out error))
                            {
                                continue;
                            }
                            sensitiveMailInfo.Status = SensitiveMailStatus.Executing;
                            provider.UpdateSensitiveMailStatus(transactionid, adminInfo, sensitiveMailInfo, out error);
                        }
                    }

                    //根据线程数量获取需要提交队列的数据
                    List <UserSensitiveMailQueueInfo> queueInfos = new List <UserSensitiveMailQueueInfo>();
                    provider.GetUserSensitiveMailQueueList(transactionid, out queueInfos, out error);
                    if (queueInfos.Count > 0)
                    {
                        Task <string[]> parent = new Task <string[]>(state =>
                        {
                            string[] result = new string[queueInfos.Count];
                            //创建并启动子任务
                            for (int i = 0; i < queueInfos.Count; i++)
                            {
                                UserSensitiveMailQueueInfo queueInfo = queueInfos[i];
                                queueInfo.Status = SensitiveMailStatus.Executing;
                                provider.UpdateUserSensitiveMailQueue(transactionid, queueInfo, string.Empty, out error);
                                var cts = new CancellationTokenSource();
                                new Task(() => { WorkerOperation(queueInfo); }, TaskCreationOptions.AttachedToParent).Start();
                            }
                            return(result);
                        }, "");
                        //任务处理完成后执行的操作
                        parent.ContinueWith(t =>
                        {
                        });
                        //启动父任务
                        parent.Start();
                    }
                    //}
                    //等待任务结束 Wait只能等待父线程结束,没办法等到父线程的ContinueWith结束
                    Thread.Sleep(TimeSpan.FromSeconds(removeSensitiveMailServiceSleepTime));
                } while (removeSensitiveMailServiceSleepTime > 0);
            }
            catch (Exception ex)
            {
                Log4netHelper.Error($"RemoveSensitiveMailQueue Exception: {ex.ToString()}");
            }
        }
Example #5
0
        public bool ExecuteSensitiveMail(Guid transactionid, AdminInfo admin, SensitiveMailInfo sensitiveMailInfo, out string strJsonResult)
        {
            bool result = true;

            strJsonResult = string.Empty;
            ErrorCodeInfo error    = new ErrorCodeInfo();
            string        message  = string.Empty;
            string        paramstr = string.Empty;

            paramstr += $"AdminID:{admin.UserID}";
            paramstr += $"||AdminAccount:{admin.UserAccount}";
            paramstr += $"||ID:{sensitiveMailInfo.ID}";

            string funname = "ExecuteSensitiveMail";

            try
            {
                do
                {
                    SensitiveMailDBProvider provider = new SensitiveMailDBProvider();
                    if (!provider.GetSensitiveMailInfo(transactionid, admin, ref sensitiveMailInfo, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }

                    if (sensitiveMailInfo.Status == SensitiveMailStatus.Executing || sensitiveMailInfo.Status == SensitiveMailStatus.Submit)
                    {
                        error.Code    = ErrorCode.SensitiveMailExecute;
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }
                    sensitiveMailInfo.Status    = SensitiveMailStatus.Submit;
                    sensitiveMailInfo.ExecuteID = transactionid;
                    if (!provider.UpdateSensitiveMailStatus(transactionid, admin, sensitiveMailInfo, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }
                    error.Code = ErrorCode.None;
                    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid);
                    strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info);

                    #region 操作日志
                    LogInfo operateLog = new LogInfo();
                    operateLog.AdminID       = admin.UserID;
                    operateLog.AdminAccount  = admin.UserAccount;
                    operateLog.RoleID        = admin.RoleID;
                    operateLog.ClientIP      = _clientip;
                    operateLog.OperateResult = true;
                    operateLog.OperateType   = "执行敏感邮件规则";
                    operateLog.OperateLog    = $"{admin.UserAccount}于{DateTime.Now}执行敏感邮件规则。" +
                                               $"名称:{sensitiveMailInfo.Name}," +
                                               $"关键字:{sensitiveMailInfo.Keywords}," +
                                               $"开始时间:{sensitiveMailInfo.StartTime}," +
                                               $"结束时间:{sensitiveMailInfo.EndTime}";
                    LogManager.AddOperateLog(transactionid, operateLog);
                    #endregion

                    result = true;
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                LoggerHelper.Error("SensitiveMailManager调用ExecuteSensitiveMail异常", paramstr, ex.ToString(), transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                result        = false;
            }
            return(result);
        }
Example #6
0
        public bool ModifySensitiveMail(Guid transactionid, AdminInfo admin, SensitiveMailInfo sensitiveMailInfo, out string strJsonResult)
        {
            bool result = true;

            strJsonResult = string.Empty;
            ErrorCodeInfo error    = new ErrorCodeInfo();
            string        message  = string.Empty;
            string        paramstr = string.Empty;

            paramstr += $"AdminID:{admin.UserID}";
            paramstr += $"||AdminAccount:{admin.UserAccount}";
            paramstr += $"||ID:{sensitiveMailInfo.ID}";
            paramstr += $"||Keywords:{sensitiveMailInfo.Keywords}";
            paramstr += $"||StartTime:{sensitiveMailInfo.StartTime}";
            paramstr += $"||EndTime:{sensitiveMailInfo.EndTime}";

            string funname = "ModifySensitiveMail";

            try
            {
                do
                {
                    error = sensitiveMailInfo.ChangeCheckProp();

                    if (error.Code != ErrorCode.None)
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }

                    SensitiveMailDBProvider provider             = new SensitiveMailDBProvider();
                    SensitiveMailInfo       oldSensitiveMailInfo = new SensitiveMailInfo();
                    oldSensitiveMailInfo.ID = sensitiveMailInfo.ID;
                    if (!provider.GetSensitiveMailInfo(transactionid, admin, ref oldSensitiveMailInfo, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }

                    if (oldSensitiveMailInfo.Status == SensitiveMailStatus.Executing)
                    {
                        error.Code    = ErrorCode.SensitiveMailIsExecuting;
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }

                    #region
                    DirectoryEntry             entry          = new DirectoryEntry();
                    CommonProvider             commonProvider = new CommonProvider();
                    List <SensitiveMailObject> members        = new List <SensitiveMailObject>();
                    List <string> distinguishedNames          = new List <string>();
                    for (int i = 0; i < sensitiveMailInfo.Objects.Count; i++)
                    {
                        if (!commonProvider.GetADEntryByGuid(sensitiveMailInfo.Objects[i].ObjectID, out entry, out message))
                        {
                            LoggerHelper.Error("ModifiedSensitiveMail调用GetADEntryByGuid异常", paramstr, message, transactionid);
                            continue;
                        }
                        SensitiveMailObject mailObject = new SensitiveMailObject();
                        mailObject.ObjectID   = sensitiveMailInfo.Objects[i].ObjectID;
                        mailObject.ObjectType = (NodeType)Enum.Parse(typeof(NodeType), entry.SchemaClassName);
                        mailObject.ObjectName = Convert.ToString(entry.Properties["name"].Value);
                        members.Add(mailObject);
                        distinguishedNames.Add(Convert.ToString(entry.Properties["distinguishedName"].Value));
                    }

                    if (!CheckdistinguishedNames(transactionid, distinguishedNames, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        LoggerHelper.Error("SensitiveMailManager调用ModifiedSensitiveMail异常", paramstr, error.Info, transactionid);
                        result = false;
                        break;
                    }
                    #endregion
                    sensitiveMailInfo.Status = SensitiveMailStatus.Enable;
                    if (!provider.ModifySensitiveMail(transactionid, admin, sensitiveMailInfo, out error))
                    {
                        strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                        LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                        result = false;
                        break;
                    }

                    for (int i = 0; i < members.Count; i++)
                    {
                        members[i].SensitiveMailID = sensitiveMailInfo.ID;
                        if (!provider.AddSensitiveMailObjects(transactionid, admin, members[i], out error))
                        {
                            strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                            LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                            result = false;
                            break;
                        }
                    }
                    error.Code = ErrorCode.None;
                    LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid);
                    strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info);

                    #region 操作日志
                    LogInfo operateLog = new LogInfo();
                    operateLog.AdminID       = admin.UserID;
                    operateLog.AdminAccount  = admin.UserAccount;
                    operateLog.RoleID        = admin.RoleID;
                    operateLog.ClientIP      = _clientip;
                    operateLog.OperateResult = true;
                    operateLog.OperateType   = "修改敏感邮件规则";
                    operateLog.OperateLog    = $"{admin.UserAccount}于{DateTime.Now}修改敏感邮件规则。" +
                                               $"原关键字:{oldSensitiveMailInfo.Keywords},现关键字:{sensitiveMailInfo.Keywords};" +
                                               $"原开始时间:{oldSensitiveMailInfo.StartTime},现开始时间:{sensitiveMailInfo.StartTime};" +
                                               $"原结束时间:{oldSensitiveMailInfo.EndTime},现结束时间:{sensitiveMailInfo.EndTime}";
                    LogManager.AddOperateLog(transactionid, operateLog);
                    #endregion

                    result = true;
                } while (false);
            }
            catch (Exception ex)
            {
                error.Code = ErrorCode.Exception;
                LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid);
                LoggerHelper.Error("SensitiveMailManager调用ModifySensitiveMail异常", paramstr, ex.ToString(), transactionid);
                strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info);
                result        = false;
            }
            return(result);
        }