using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Generic;
using Spaces;
using Spaces.Controls;

public partial class Manage_DisallowedIP : ManagePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    　
        if (!IsPostBack)
            BindAccount();
    }

    private void BindAccount()
    {
        List<string> list = SiteTools.GetDisallowedWords(CheckType.IPAddress);
        StringBuilder sb = new StringBuilder();
        foreach (string str in list)
        {

           
            sb.AppendFormat("{0}\n",str);

        }
        distext.Text = sb.ToString();
    }
    protected void disnow_Click(object sender, EventArgs e)
    {
        string[] names = distext.Text.Trim().Split('\n');
        List<string> list = new List<string>();
        foreach (string s in names)
        {
            string str = s.Trim();
            /*for (int i = 0; i < str.Length; i++)
            {
                int ncode = (int)str[i];
               if (str[i] != ' ' && str[i] != '.' && (ncode < 48 || ncode > 57))
                {
                    string msg = "<script>alert('IP地址" + str.Trim() + "无效!');</script>";
                    Message.Text = msg;
                    return;
                }
            }
             * */
           // string msg1 = "<script>alert('IP地址" + Ip_to_longStr(str) + "无效!');</script>";
          //  Message.Text+= msg1;
            if (str == string.Empty)
                continue;
            list.Add(s);
        }
        SpacesDataProvider.Instance().CreateDisallowedWords(list,CheckType.IPAddress);
        SiteTools.ClearCacheDisallowedWords(CheckType.IPAddress);
        BindAccount();
        PageMsg.Text = Msg.GetMsg("修改禁用IP成功！");
    }

    private string Ip_to_longStr(string ip)
    {
        string retVal = "";

        string[] str = ip.Split(new char[] { '.' });

 
        foreach (string ipBlock in str)
        {
            string buff = ipBlock;
     
            if (ipBlock.Length < 3)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (buff.Length >= 3)
                    {
                        break;
                    }
                    buff = "0" + buff;
                }
            }

            retVal += buff;
        }

        return retVal;
    }
}

