示例#1
0
        public async Task <IActionResult> GetFileList(int datasetId, CancellationToken cancellationToken = default)
        {
            var clientIp = IpAddressUtil.GetClientIp(HttpContext);
            var files    = await _datasetFileService.GetFileListAsync(datasetId, clientIp, cancellationToken);

            return(new JsonResult(files));
        }
示例#2
0
        public async Task <IActionResult> GetFileDeleteSasToken(int datasetId, CancellationToken cancellationToken = default)
        {
            var clientIp       = IpAddressUtil.GetClientIp(HttpContext);
            var sasTokenDelete = await _datasetFileService.GetFileDeleteUriBuilderWithSasTokenAsync(datasetId, clientIp, cancellationToken);

            return(new JsonResult(sasTokenDelete));
        }
        public async Task <IActionResult> CreateStudySpecificDataSetAsync(int studyId, DatasetCreateUpdateInputBaseDto newDataset, CancellationToken cancellation = default)
        {
            var clientIp = IpAddressUtil.GetClientIp(HttpContext);

            var updatedStudy = await _studySpecificDatasetService.CreateStudySpecificDatasetAsync(studyId, newDataset, clientIp, cancellation);

            return(new JsonResult(updatedStudy));
        }
        public void Faz_uso_do_header_da_akamai()
        {
            var http = new HttpRequestMessage();

            http.Headers.Add("X-Forwarded-For", "177.96.44.32, 23.50.52.13, 23.50.52.23");
            http.Headers.Add("True-Client-IP", "127.0.0.1");

            var ip = http.GetClientIpAddress();
            var i  = IpAddressUtil.ParseIp(ip);
        }
示例#5
0
        public string ResolveIp()
        {
            IPAddress clientIp = null;

            var httpContent = _httpContextAccessor.HttpContext;

            if (httpContent.Request.Headers.TryGetValue(_headerName, out var values))
            {
                clientIp = IpAddressUtil.ParseIp(values.Last());
            }

            return(clientIp?.ToString());
        }
示例#6
0
        /// <summary>
        /// 根据相关信息,写入用户的操作日志记录
        /// 主要用于写操作模块日志
        /// </summary>
        /// <param name="module">操作模块名称</param>
        /// <param name="operationType">操作类型</param>
        /// <param name="note">操作详细表述</param>
        /// <param name="currentUser">操作用户</param>
        /// <returns></returns>
        public bool OnOperationLog(string module, string operationType, string note, YuebonCurrentUser currentUser)
        {
            //虽然实现了这个事件,但是我们还需要判断该表是否在配置表里面,如果不在,则不记录操作日志。
            //OperationLogSettingInfo settingInfo = BLLFactory<OperationLogSetting>.Instance.FindByTableName(tableName, trans);

            if (currentUser != null)
            {
                bool login      = operationType == DbLogType.Login.ToString();
                bool visit      = operationType == DbLogType.Visit.ToString();
                bool exit       = operationType == DbLogType.Exit.ToString();
                bool other      = operationType == DbLogType.Other.ToString();
                bool insert     = operationType == DbLogType.Create.ToString();
                bool update     = operationType == DbLogType.Update.ToString();
                bool delete     = operationType == DbLogType.Delete.ToString();
                bool deletesoft = operationType == DbLogType.DeleteSoft.ToString();
                bool exception  = operationType == DbLogType.Exception.ToString();
                if (login || visit || exit || other || insert || update || delete || deletesoft || exception)
                {
                    Log info = new Log();
                    info.ModuleName    = module;
                    info.Type          = operationType;
                    info.Description   = note;
                    info.Date          = info.CreatorTime = DateTime.Now;
                    info.CreatorUserId = currentUser.UserId;
                    info.Account       = currentUser.Account;
                    info.NickName      = currentUser.NickName;
                    info.OrganizeId    = currentUser.OrganizeId;
                    info.IPAddress     = currentUser.CurrentLoginIP;
                    info.IPAddressName = IpAddressUtil.GetCityByIp(currentUser.CurrentLoginIP);
                    info.Result        = true;
                    long lg = _iLogRepository.Insert(info);
                    if (lg > 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#7
0
 public static bool IsIPMatched(this string ip, string pattern)
 {
     return(IpAddressUtil.ContainsIp(pattern, ip));
 }
示例#8
0
        public async Task <IActionResult> GetCheckUser(string username, string password, string vcode, string vkey, string appId, string systemCode)
        {
            CommonResult      result            = new CommonResult();
            RemoteIpParser    remoteIpParser    = new RemoteIpParser();
            string            strIp             = remoteIpParser.GetClientIp(HttpContext).MapToIPv4().ToString();
            YuebonCacheHelper yuebonCacheHelper = new YuebonCacheHelper();
            var    vCode = yuebonCacheHelper.Get("ValidateCode" + vkey);
            string code  = vCode != null?vCode.ToString() : "11";

            if (vcode.ToUpper() != code)
            {
                result.ErrMsg = "验证码错误";
                return(ToJsonContent(result));
            }
            Log  logEntity = new Log();
            bool blIp      = _filterIPService.ValidateIP(strIp);

            if (blIp)
            {
                result.ErrMsg = strIp + "该IP已被管理员禁止登录!";
            }
            else
            {
                if (string.IsNullOrEmpty(username))
                {
                    result.ErrMsg = "用户名不能为空!";
                }
                else if (string.IsNullOrEmpty(password))
                {
                    result.ErrMsg = "密码不能为空!";
                }
                if (string.IsNullOrEmpty(systemCode))
                {
                    result.ErrMsg = ErrCode.err40006;
                }
                else
                {
                    string strHost = Request.Host.ToString();
                    APP    app     = _appService.GetAPP(appId);
                    if (app == null)
                    {
                        result.ErrCode = "40001";
                        result.ErrMsg  = ErrCode.err40001;
                    }
                    else
                    {
                        if (!app.RequestUrl.Contains(strHost, StringComparison.Ordinal) && !strHost.Contains("localhost", StringComparison.Ordinal))
                        {
                            result.ErrCode = "40002";
                            result.ErrMsg  = ErrCode.err40002 + ",你当前请求主机:" + strHost;
                        }
                        else
                        {
                            SystemType systemType = _systemTypeService.GetByCode(systemCode);
                            if (systemType == null)
                            {
                                result.ErrMsg = ErrCode.err40006;
                            }
                            else
                            {
                                Tuple <User, string> userLogin = await this._userService.Validate(username, password);

                                if (userLogin != null)
                                {
                                    string ipAddressName = IpAddressUtil.GetCityByIp(strIp);
                                    if (userLogin.Item1 != null)
                                    {
                                        result.Success = true;
                                        User              user           = userLogin.Item1;
                                        JwtOption         jwtModel       = App.GetService <JwtOption>();
                                        TokenProvider     tokenProvider  = new TokenProvider(jwtModel);
                                        TokenResult       tokenResult    = tokenProvider.LoginToken(user, appId);
                                        YuebonCurrentUser currentSession = new YuebonCurrentUser
                                        {
                                            UserId         = user.Id,
                                            Name           = user.RealName,
                                            AccessToken    = tokenResult.AccessToken,
                                            AppKey         = appId,
                                            CreateTime     = DateTime.Now,
                                            Role           = _roleService.GetRoleEnCode(user.RoleId),
                                            ActiveSystemId = systemType.Id,
                                            CurrentLoginIP = strIp,
                                            IPAddressName  = ipAddressName
                                        };
                                        TimeSpan expiresSliding = DateTime.Now.AddMinutes(120) - DateTime.Now;
                                        yuebonCacheHelper.Add("login_user_" + user.Id, currentSession, expiresSliding, true);

                                        List <AllowCacheApp> list = yuebonCacheHelper.Get("AllowAppId").ToJson().ToList <AllowCacheApp>();
                                        if (list.Count == 0)
                                        {
                                            IEnumerable <APP> appList = _appService.GetAllByIsNotDeleteAndEnabledMark();
                                            yuebonCacheHelper.Add("AllowAppId", appList);
                                        }
                                        CurrentUser    = currentSession;
                                        result.ResData = currentSession;
                                        result.ErrCode = ErrCode.successCode;
                                        result.Success = true;

                                        logEntity.Account       = user.Account;
                                        logEntity.NickName      = user.NickName;
                                        logEntity.Date          = logEntity.CreatorTime = DateTime.Now;
                                        logEntity.IPAddress     = CurrentUser.CurrentLoginIP;
                                        logEntity.IPAddressName = CurrentUser.IPAddressName;
                                        logEntity.Result        = true;
                                        logEntity.ModuleName    = "登录";
                                        logEntity.Description   = "登录成功";
                                        logEntity.Type          = "Login";
                                        _logService.Insert(logEntity);
                                    }
                                    else
                                    {
                                        result.ErrCode          = ErrCode.failCode;
                                        result.ErrMsg           = userLogin.Item2;
                                        logEntity.Account       = username;
                                        logEntity.Date          = logEntity.CreatorTime = DateTime.Now;
                                        logEntity.IPAddress     = strIp;
                                        logEntity.IPAddressName = ipAddressName;
                                        logEntity.Result        = false;
                                        logEntity.ModuleName    = "登录";
                                        logEntity.Type          = "Login";
                                        logEntity.Description   = "登录失败," + userLogin.Item2;
                                        _logService.Insert(logEntity);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            yuebonCacheHelper.Remove("LoginValidateCode");
            return(ToJsonContent(result, true));
        }
示例#9
0
        public IActionResult SysConnect(string openmf, string appId, string systemCode)
        {
            CommonResult   result         = new CommonResult();
            RemoteIpParser remoteIpParser = new RemoteIpParser();
            string         strIp          = remoteIpParser.GetClientIp(HttpContext).MapToIPv4().ToString();

            if (string.IsNullOrEmpty(openmf))
            {
                result.ErrMsg = "切换参数错误!";
            }

            bool blIp = _filterIPService.ValidateIP(strIp);

            if (blIp)
            {
                result.ErrMsg = strIp + "该IP已被管理员禁止登录!";
            }
            else
            {
                string ipAddressName = IpAddressUtil.GetCityByIp(strIp);
                if (string.IsNullOrEmpty(systemCode))
                {
                    result.ErrMsg = ErrCode.err40006;
                }
                else
                {
                    string strHost = Request.Host.ToString();
                    APP    app     = _appService.GetAPP(appId);
                    if (app == null)
                    {
                        result.ErrCode = "40001";
                        result.ErrMsg  = ErrCode.err40001;
                    }
                    else
                    {
                        if (!app.RequestUrl.Contains(strHost, StringComparison.Ordinal) && !strHost.Contains("localhost", StringComparison.Ordinal))
                        {
                            result.ErrCode = "40002";
                            result.ErrMsg  = ErrCode.err40002 + ",你当前请求主机:" + strHost;
                        }
                        else
                        {
                            SystemType systemType = _systemTypeService.GetByCode(systemCode);
                            if (systemType == null)
                            {
                                result.ErrMsg = ErrCode.err40006;
                            }
                            else
                            {
                                YuebonCacheHelper yuebonCacheHelper = new YuebonCacheHelper();
                                object            cacheOpenmf       = yuebonCacheHelper.Get("openmf" + openmf);
                                yuebonCacheHelper.Remove("openmf" + openmf);
                                if (cacheOpenmf == null)
                                {
                                    result.ErrCode = "40007";
                                    result.ErrMsg  = ErrCode.err40007;
                                }
                                else
                                {
                                    User user = _userService.Get(cacheOpenmf.ToString());
                                    if (user != null)
                                    {
                                        result.Success = true;
                                        JwtOption         jwtModel       = App.GetService <JwtOption>();
                                        TokenProvider     tokenProvider  = new TokenProvider(jwtModel);
                                        TokenResult       tokenResult    = tokenProvider.LoginToken(user, appId);
                                        YuebonCurrentUser currentSession = new YuebonCurrentUser
                                        {
                                            UserId          = user.Id,
                                            Name            = user.RealName,
                                            AccessToken     = tokenResult.AccessToken,
                                            AppKey          = appId,
                                            CreateTime      = DateTime.Now,
                                            Role            = _roleService.GetRoleEnCode(user.RoleId),
                                            ActiveSystemId  = systemType.Id,
                                            CurrentLoginIP  = strIp,
                                            IPAddressName   = ipAddressName,
                                            ActiveSystemUrl = systemType.Url
                                        };
                                        TimeSpan expiresSliding = DateTime.Now.AddMinutes(120) - DateTime.Now;
                                        yuebonCacheHelper.Add("login_user_" + user.Id, currentSession, expiresSliding, true);
                                        CurrentUser    = currentSession;
                                        result.ResData = currentSession;
                                        result.ErrCode = ErrCode.successCode;
                                        result.Success = true;
                                    }
                                    else
                                    {
                                        result.ErrCode = ErrCode.failCode;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(ToJsonContent(result));
        }
        public void IsPrivateIpAddress_PublicIpAddressWithInitialSpace_ReturnsFalse()
        {
            bool result = IpAddressUtil.IsPrivateIpAddress(" 8.8.8.8");

            Assert.Equal(false, result);
        }
        public void IsPrivateIpAddress_PrivateAddressIpv6WithPort_ReturnsTrue()
        {
            bool result = IpAddressUtil.IsPrivateIpAddress("[fd74:20cf:81a2::]:5555");

            Assert.Equal(true, result);
        }
        public void IsPrivateIpAddress_PrivateAddressWithPort_ReturnsTrue()
        {
            bool result = IpAddressUtil.IsPrivateIpAddress("10.0.0.1:5555");

            Assert.Equal(true, result);
        }
        public void IsPrivateIpAddress_PrivateAddressIpv6_ReturnsFalse()
        {
            bool result = IpAddressUtil.IsPrivateIpAddress("fd74:20cf:81a2::");

            Assert.Equal(true, result);
        }
        public void IsPrivateIpAddress_PublicAddressIpv6_ReturnsFalse()
        {
            bool result = IpAddressUtil.IsPrivateIpAddress("2001:4860:4860::8888");

            Assert.Equal(false, result);
        }
示例#15
0
 protected string GetIP()
 {
     return(IpAddressUtil.GetClientIpAddress());
 }