Exemple #1
0
        /// <summary>
        /// 加载配置
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static List <FWUser> LoadConfig()
        {
            //string xml = UserManager.BasePath + "\\accont.xml";
            List <FWUser> lstRet = new List <FWUser>();

            if (!File.Exists(XmlPath))
            {
                return(lstRet);
            }
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(XmlPath);
                XmlNodeList lstRule = doc.GetElementsByTagName("account");

                FWUser user = null;
                foreach (XmlNode node in lstRule)
                {
                    user = new FWUser();
                    XmlAttribute att = node.Attributes["name"];
                    if (att != null)
                    {
                        user.Name = att.InnerText;
                    }

                    att = node.Attributes["url"];
                    if (att != null)
                    {
                        user.Url = att.InnerText;
                    }
                    att = node.Attributes["username"];
                    if (att != null)
                    {
                        user.UserName = att.InnerText;
                    }
                    att = node.Attributes["secretkey"];
                    if (att != null)
                    {
                        user.Secret = att.InnerText;
                    }
                    att = node.Attributes["iplist"];
                    if (att != null)
                    {
                        user._ipList = JsonConvert.DeserializeObject <List <IpItem> >(att.InnerText);
                    }
                    att = node.Attributes["multipleIP"];
                    if (att != null)
                    {
                        user.MultipleIP = att.InnerText == "1";
                    }
                    lstRet.Add(user);
                }
            }
            catch
            {
            }
            return(lstRet);
        }
        /// <summary>
        /// 加载信息
        /// </summary>
        public APIResault LoadInfo()
        {
            _fwHandle = LoadAdapter();

            if (_fwHandle == null)
            {
                return(ApiCommon.GetFault("没有可用的防火墙进程"));
            }
            _fwHandle.AllUser = FWUser.LoadConfig();

            return(ApiCommon.GetSuccess());
        }
Exemple #3
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public APIResault AddUser(FWUser user)
        {
            foreach (FWUser u in _lstUser)
            {
                if (u.UserName == user.UserName)
                {
                    return(ApiCommon.GetFault("已存在用户:" + user.UserName));
                }
            }
            _lstUser.Add(user);

            return(ApiCommon.GetSuccess());
        }
Exemple #4
0
        /// <summary>
        /// 保存信息
        /// </summary>
        public void SaveConfig()
        {
            string path = BasePath + "userInfo.xml";

            FWUser.SaveConfig(_lstUser);
        }
Exemple #5
0
 /// <summary>
 /// 加载用户信息
 /// </summary>
 public void LoadUser()
 {
     _lstUser = FWUser.LoadConfig();
 }
Exemple #6
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());
        }
        /// <summary>
        /// 保存信息
        /// </summary>
        public void SaveConfig()
        {
            string path = BasePath + "userInfo.xml";

            FWUser.SaveConfig(_fwHandle.AllUser);
        }