Exemplo n.º 1
0
        /// <summary>
        /// 执行函数
        /// </summary>
        private APIResault DoMethods(HttpListenerRequest request)
        {
            ServiceRequest req = new ServiceRequest();

            req.Load(request);
            string arg    = req.GetArgString();
            string method = req.MethodName;
            string url    = request.Url.AbsolutePath;

            if (string.IsNullOrWhiteSpace(method))
            {
                return(ApiCommon.GetFault("函数MethodName不能为空"));
            }
            try
            {
                APIResault con = RunMethod(url, method, arg, request);
                if (_message != null && _message.ShowLog)
                {
                    string mess = con.Message;

                    _message.Log(mess);
                }
                return(con);
            }
            catch (Exception ex)
            {
                if (OnException != null)
                {
                    OnException(ex);
                }
                return(ApiCommon.GetException(ex));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 执行函数
        /// </summary>
        private APIResault DoMethods(HttpListenerRequest request)
        {
            ServiceRequest req = new ServiceRequest();

            req.Load(request);
            string arg    = req.GetArgString();
            string method = req.MethodName;
            string url    = request.Url.AbsolutePath;
            string ip     = LanUnit.GetHostAddress(request);


            if (_lanUnit != null && _lanUnit.IsAllowIP(ip))
            {
                return(ApiCommon.GetException(new System.Net.WebException("调用IP:" + ip + "不在白名单内")));
            }

            if (string.IsNullOrWhiteSpace(method))
            {
                return(ApiCommon.GetFault("函数MethodName不能为空"));
            }
            try
            {
                APIResault con = RunMethod(url, method, arg, request);
                if (_message != null && _message.ShowLog)
                {
                    string mess = con.Message;

                    _message.Log(mess);
                }
                return(con);
            }
            catch (Exception ex)
            {
                if (OnException != null)
                {
                    OnException(ex);
                }
                return(ApiCommon.GetException(ex));
            }
        }
Exemplo n.º 3
0
        public APIResault UpdateAddress(string args, HttpListenerRequest request)
        {
            string remoteIP = GetIP(request);
            string blockkey = KeyHead + remoteIP;

            long curTick = (long)CommonMethods.ConvertDateTimeInt(DateTime.Now, true, true);

            APIResault res = CheckBlockIP(blockkey, remoteIP, curTick);

            if (!res.IsSuccess)
            {
                return(res);
            }


            ArgValues arg  = ApiCommon.GetArgs(args);
            long      tick = arg.GetDataValue <long>("Tick");
            string    name = arg.GetDataValue <string>("Name");
            string    sign = arg.GetDataValue <string>("Sign");

            res = CheckPacket(curTick, name, tick);
            if (!res.IsSuccess)
            {
                return(res);
            }

            FWUser user = _userMan.GetUser(name);

            if (user == null)
            {
                return(ApiCommon.GetFault("找不到用户:" + name));
            }

            string cntkey = KeyCntHead + remoteIP;

            string cursign = user.GetSign(tick);

            if (!string.Equals(cursign, sign, StringComparison.CurrentCultureIgnoreCase))
            {
                int times = _cache.GetValue <int>(cntkey);
                times++;
                string err = null;
                if (times >= BlockTimes)
                {
                    _cache.SetValue <long>(blockkey, curTick, SetValueType.Set, BlockSecond);
                    _cache.DeleteValue(cntkey);
                    err = "效验错误,IP被屏蔽:" + remoteIP;
                }
                else
                {
                    _cache.SetValue <int>(cntkey, times, SetValueType.Set, BlockSecond);
                    err = "效验错误,错误次数:" + times;
                }
                return(ApiCommon.GetFault(err));
            }
            _cache.DeleteValue(cntkey);
            if (!user.UpdateIP(remoteIP))
            {
                return(ApiCommon.GetSuccess());
            }
            _userMan.RefreashFirewall();
            _userMan.SaveConfig();
            _form.OnUserUpdate();
            if (_message != null && _message.ShowLog)
            {
                _message.Log("用户:" + name + ",的IP更新为:" + remoteIP);
            }
            return(ApiCommon.GetSuccess());
        }