Exemplo n.º 1
0
 private void btnAddIP_Click(object sender, EventArgs e)
 {
     if (cboPoolIp.EditValue == null)
     {
         Class.App.InputNotAccess();
         return;
     }
     if (txtIpAddress.Text == "")
     {
         Class.App.InputNotAccess();
         return;
     }
     if (txtMacAddress.Text == "")
     {
         Class.App.InputNotAccess();
         return;
     }
     Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
     cls.IpAddress  = ipaddress;
     cls.PoolPublic = cboPoolIp.EditValue.ToString();
     cls.IpPublic   = txtIpAddress.Text;
     cls.MacPc      = txtMacAddress.Text;
     cls.Note       = txtNote.Text;
     if (cls.NW_Dhcp_Customer_UpdateIPStatic_MySQL())
     {
         Class.App.SaveSuccessfully();
         add_edit = true;
     }
     else
     {
         Class.App.SaveNotSuccessfully();
     }
     this.Close();
 }
Exemplo n.º 2
0
 private void btnAddIP_Click(object sender, EventArgs e)
 {
     if (cboPoolIp.EditValue == null)
     {
         Class.App.InputNotAccess();
         return;
     }
     if (txtIpAddress.Text == "")
     {
         Class.App.InputNotAccess();
         return;
     }
     if (txtMacAddress.Text == "")
     {
         Class.App.InputNotAccess();
         return;
     }
     Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
     cls.IpAddress = ipaddress;
     cls.PoolPublic = cboPoolIp.EditValue.ToString();
     cls.IpPublic = txtIpAddress.Text;
     cls.MacPc = txtMacAddress.Text;
     cls.Note = txtNote.Text;
     if (cls.NW_Dhcp_Customer_UpdateIPStatic_MySQL())
     {
         Class.App.SaveSuccessfully();
         add_edit = true;
     }
     else
     {
         Class.App.SaveNotSuccessfully();
     }
     this.Close();
 }
Exemplo n.º 3
0
        private void cboPoolIp_EditValueChanged(object sender, EventArgs e)
        {
            Class.NW_Dhcp_Ip       cls    = new Class.NW_Dhcp_Ip();
            Class.NW_Dhcp_Customer clscus = new Class.NW_Dhcp_Customer();
            clscus.PoolIp = cboPoolIp.EditValue.ToString();
            DataTable dtcus = clscus.NW_Dhcp_Customer_GetbyPool_MySQL();

            cls.PoolIp = cboPoolIp.EditValue.ToString();
            DataTable dt    = cls.NW_Dhcp_Ip_GetIPbyPool_MySQL();
            string    ip    = "";
            bool      check = false;;

            if (dt.Rows.Count > 0)
            {
                string   range = dt.Rows[0]["RangeIP"].ToString();
                string[] cat   = range.Split(' ');
                if (cat.Length > 1)
                {
                    txtIpAddress.Properties.Items.Clear();
                    string[] temp  = cat[0].Split('.');
                    int      start = 0;
                    int      end   = 0;
                    if (temp.Length > 2)
                    {
                        start = int.Parse(temp[3]);
                    }
                    temp = cat[1].Split('.');
                    if (temp.Length > 2)
                    {
                        end = int.Parse(temp[3]);
                    }

                    for (int i = start; i < end; i++)
                    {
                        ip    = temp[0] + "." + temp[1] + "." + temp[2] + "." + i.ToString();
                        check = false;
                        for (int j = 0; j < dtcus.Rows.Count; j++)
                        {
                            if (ip == dtcus.Rows[j]["IpAddress"].ToString())
                            {
                                check = true;
                            }
                        }
                        if (check == false)
                        {
                            txtIpAddress.Properties.Items.Add(ip);
                        }
                    }
                }
            }
            if (txtIpAddress.Properties.Items.Count > 0)
            {
                txtIpAddress.Text = txtIpAddress.Properties.Items[0].ToString();
            }
            else
            {
                txtIpAddress.Text = "";
            }
        }
Exemplo n.º 4
0
        private void cboPoolIp_EditValueChanged(object sender, EventArgs e)
        {
            Class.NW_Dhcp_Ip cls = new Class.NW_Dhcp_Ip();
            Class.NW_Dhcp_Customer clscus = new Class.NW_Dhcp_Customer();
            clscus.PoolIp = cboPoolIp.EditValue.ToString();
            DataTable dtcus = clscus.NW_Dhcp_Customer_GetbyPoolPublic_MySQL();
            cls.PoolIp = cboPoolIp.EditValue.ToString();
            DataTable dt = cls.NW_Dhcp_Ip_GetIPbyPool_MySQL();
            string ip = "";
            bool check = false; ;
            if (dt.Rows.Count > 0)
            {
                string range = dt.Rows[0]["RangeIP"].ToString();
                string[] cat = range.Split(' ');
                if (cat.Length > 1)
                {
                    txtIpAddress.Properties.Items.Clear();
                    string[] temp = cat[0].Split('.');
                    int start = 0;
                    int end = 0;
                    if (temp.Length > 2)
                    {
                        start = int.Parse(temp[3]);
                    }
                    temp = cat[1].Split('.');
                    if (temp.Length > 2)
                    {
                        end = int.Parse(temp[3]);
                    }

                    for (int i = start; i < end; i++)
                    {
                        ip = temp[0] + "." + temp[1] + "." + temp[2] + "." + i.ToString();
                        check = false;
                        for (int j = 0; j < dtcus.Rows.Count; j++)
                        {
                            if (ip == dtcus.Rows[j]["IpPublic"].ToString())
                            {
                                check = true;
                            }

                        }
                        if (check == false)
                        {
                            txtIpAddress.Properties.Items.Add(ip);
                        }

                    }
                }
            }
            if (txtIpAddress.Properties.Items.Count > 0)
            {
                txtIpAddress.Text = txtIpAddress.Properties.Items[0].ToString();
            }
            else
            {
                txtIpAddress.Text = "";
            }
        }
Exemplo n.º 5
0
 private void btnDeleteAll_Click(object sender, EventArgs e)
 {
     Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
     if (cls.NW_Dhcp_Customer_DeleteAll_MySQL())
     {
         MessageBox.Show("Đã xóa xong! ");
     }
 }
Exemplo n.º 6
0
 public void NW_Dhcp_Customer_Getlist()
 {
     //  Waiting.ShowWaitForm();
        // Waiting.SetWaitFormDescription("Đang tải thông tin khách hàng");
     Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
     dt = cls.NW_Dhcp_Customer_Getlist();
     dtIpPublic = cls.NW_Dhcp_Customer_Getlist();
     gridItem.DataSource = dt;
      //   Waiting.CloseWaitForm();
 }
Exemplo n.º 7
0
 public void NW_Dhcp_Customer_Getlist()
 {
     //  Waiting.ShowWaitForm();
     // Waiting.SetWaitFormDescription("Đang tải thông tin khách hàng");
     Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
     dt                  = cls.NW_Dhcp_Customer_Getlist();
     dtIpPublic          = cls.NW_Dhcp_Customer_Getlist();
     gridItem.DataSource = dt;
     //   Waiting.CloseWaitForm();
 }
Exemplo n.º 8
0
 private void btnDelIP_Click(object sender, EventArgs e)
 {
     Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
     cls.IpAddress = gridItemDetail.GetFocusedRowCellValue(colIpAddress).ToString();
     if (cls.NW_Dhcp_Customer_DeleteIPStatic_MySQL())
     {
         MessageBox.Show("Xóa IP Static thành công !");
         NW_Dhcp_Customer_Getlist_MySQL();
     }
     else
     {
         MessageBox.Show("Xóa IP Static thất bại !");
     }
 }
Exemplo n.º 9
0
        private void call_info(string Form_name, string code)
        {
            Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
            cls.IpAddress = code;
            DataTable dt = cls.NW_Dhcp_Customer_GetbyIp_MySQL();

            txtMacAddress.Text      = dt.Rows[0]["MacAddress"].ToString();
            cboPoolIp.EditValue     = dt.Rows[0]["PoolIp"].ToString();
            txtIpAddress.Text       = dt.Rows[0]["IpAddress"].ToString();
            txtCustomerCode.Text    = dt.Rows[0]["CustomerCode"].ToString();
            txtCustomerAddress.Text = dt.Rows[0]["CustomerAddress"].ToString();
            txtCustomerName.Text    = dt.Rows[0]["CustomerName"].ToString();
            cboBootfile.Text        = dt.Rows[0]["Bootfile"].ToString();
            txtLocation.Text        = dt.Rows[0]["Location"].ToString();
            txtNote.Text            = dt.Rows[0]["Note"].ToString();
            txtIpAddress.Enabled    = false;
            cboPoolIp.Enabled       = false;
        }
Exemplo n.º 10
0
        private void txtMacAddress_Validated(object sender, EventArgs e)
        {
            txtMacAddress.Text = txtMacAddress.Text.Replace("-", ":").ToLower();
            string input = txtMacAddress.Text;
            // input = input.Replace(" ", "").Replace(":", "").Replace("-", "");

            Regex r = new Regex("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$");


            if (!r.IsMatch(input))
            {
                MessageBox.Show(" Mac Address không hợp lệ ! ");
                txtMacAddress.Focus();
            }
            if (txtIpAddress.Enabled)
            {
                Class.NW_Dhcp_Customer clscus = new Class.NW_Dhcp_Customer();
                clscus.MacAddress = txtMacAddress.Text;
                DataTable dt = clscus.NW_Dhcp_Customer_GetbyMacaddress_MySQL();
                if (dt.Rows.Count > 0)
                {
                    MessageBox.Show(" Mac Address đã có, vui lòng chọn mac khác ! ");
                    txtMacAddress.Focus();
                }
            }
            else
            {
                // truong hop sua nhung co roi cung ko dc update
                Class.NW_Dhcp_Customer clscus = new Class.NW_Dhcp_Customer();
                clscus.MacAddress = txtMacAddress.Text;
                clscus.IpAddress  = txtIpAddress.Text;
                DataTable dt = clscus.NW_Dhcp_Customer_GetbyMacaddress_MySQL();
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["IpAddress"].ToString() != clscus.IpAddress)
                    {
                        MessageBox.Show(" Mac Address đã có, vui lòng chọn mac khác ! ");
                        txtMacAddress.Focus();
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void btnDel_Click(object sender, EventArgs e)
        {
            if (Class.App.ConfirmDeletion() == DialogResult.No)
            {
                return;
            }
            Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
            string IP = "";

            IP            = gridItemDetail.GetFocusedRowCellValue(colIpAddress).ToString();
            cls.IpAddress = IP;
            if (cls.NW_Dhcp_Customer_Delete_MySQL())
            {
                Class.App.DeleteSuccessfully(IP);
                NW_Dhcp_Customer_Getlist_MySQL();
            }
            else
            {
                Class.App.DeleteNotSuccessfully();
            }
        }
Exemplo n.º 12
0
 private void btnImport_Click(object sender, EventArgs e)
 {
     if (dt.Rows.Count > 0)
     {
         Waiting.ShowWaitForm();
         Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
         string fail = "";
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             Application.DoEvents();
             Waiting.SetWaitFormDescription("Đang lưu ...(" + (i + 1).ToString() + ")");
             cls.IpAddress       = dt.Rows[i]["IpAddress"].ToString();
             cls.MacAddress      = dt.Rows[i]["MacAddress"].ToString();
             cls.MacAddress_CMTS = dt.Rows[i]["MacAddress_CMTS"].ToString();
             cls.CustomerCode    = dt.Rows[i]["CustomerCode"].ToString();
             cls.CustomerName    = dt.Rows[i]["CustomerName"].ToString();
             cls.CustomerAddress = dt.Rows[i]["CustomerAddress"].ToString();
             cls.PoolIp          = dt.Rows[i]["PoolIp"].ToString();
             cls.Bootfile        = dt.Rows[i]["Bootfile"].ToString();
             cls.IpPublic        = dt.Rows[i]["IpPublic"].ToString();
             cls.MacPc           = dt.Rows[i]["MacPc"].ToString();
             cls.PoolPublic      = dt.Rows[i]["PoolPublic"].ToString();
             cls.Location        = dt.Rows[i]["Location"].ToString();
             cls.Note            = dt.Rows[i]["Note"].ToString();
             //if (cls.IpAddress == "192.168.11.63")
             //{
             //    string degug = "";
             //}
             if (!cls.InsertMySQL()) // thay the import vao dl binh thuong thi impoort vao Mysql server co DHCP SV
             {
                 fail += "\r\n" + dt.Rows[i]["IpAddress"].ToString();
             }
         }
         Waiting.CloseWaitForm();
         //MessageBox.Show("Hoàn thành Insert !");
         //MessageBox.Show(fail);
     }
 }
Exemplo n.º 13
0
        private void btnCreateDHCPFile_Click(object sender, EventArgs e)
        {
            try
            {
                if (dt.Rows.Count > 0)
                {
                    if (System.IO.File.Exists(@"dhcpd.conf.temp"))
                    {
                        string                 txt          = System.IO.File.ReadAllText(@"dhcpd.conf.temp");
                        string                 CPEDynamic   = "";
                        string                 CPEStatic    = "";
                        string                 PoolModem    = "";
                        Class.NW_Dhcp_Ip       clsIP        = new Class.NW_Dhcp_Ip();
                        Class.NW_Dhcp_Customer clsModem     = new Class.NW_Dhcp_Customer();
                        DataTable              dtCPEDynamic = clsIP.NW_Dhcp_Ip_GetbyCPEDynamic_MySQL();
                        DataTable              dtCPEStatic  = clsIP.NW_Dhcp_Ip_GetbyCPEStatic_MySQL();
                        DataTable              dtPoolModem  = clsIP.NW_Dhcp_Ip_GetbyPoolModem_MySQL();
                        #region CPEDynamic
                        for (int i = 0; i < dtCPEDynamic.Rows.Count; i++)
                        {
                            CPEDynamic += "\tsubnet " + dtCPEDynamic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                          "\t\tauthoritative;\n" +
                                          "\t\toption subnet-mask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                          "\t\toption domain-name-servers " + dtCPEDynamic.Rows[i]["Dns"].ToString() + ";\n" +
                                          "\t\toption routers " + dtCPEDynamic.Rows[i]["Router"].ToString() + ";\n" +
                                          "\t\toption broadcast-address " + dtCPEDynamic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                          "\t\tpool {\n" +
                                          "\t\trange " + dtCPEDynamic.Rows[i]["RangeIP"].ToString() + ";\n" +
                                          "\t\t}\n" +
                                          "\t}\n" +
                                          "\tgroup {\n" +
                                          "\t\tuse-host-decl-names on;\n" +
                                          "\t}\n";
                        }
                        #endregion
                        #region CPEStatic
                        for (int i = 0; i < dtCPEStatic.Rows.Count; i++)
                        {
                            clsModem.PoolIp = dtCPEStatic.Rows[i]["PoolIp"].ToString();
                            DataTable dtmodem  = clsModem.NW_Dhcp_Customer_GetbyPoolPublic_MySQL();
                            string    txtmodem = "";
                            for (int j = 0; j < dtmodem.Rows.Count; j++)
                            {
                                string ipcpe = dtmodem.Rows[j]["IpPublic"].ToString();
                                ipcpe = ipcpe.Replace(":", "-");
                                string reIPcpe = dtmodem.Rows[j]["MacPc"].ToString().Replace(":", "");
                                txtmodem += "\t\t# PC an Modem " + dtmodem.Rows[j]["IpAddress"].ToString() + " " + dtmodem.Rows[j]["Note"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                            "\t\thost " + ipcpe + " {\n" +
                                            "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacPc"].ToString() + " ;\n" +
                                            "\t\t\tfixed-address " + dtmodem.Rows[j]["IpPublic"].ToString() + ";\n" +
                                            "\t\t\toption host-name 	\"mt"+ reIPcpe + "\";\n" +
                                            "\t\t\tddns-hostname 	\"mt"+ reIPcpe + "\";\n" +
                                            "\t\t}\n";
                            }

                            CPEStatic += "\tsubnet " + dtCPEStatic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                         "\t\tauthoritative;\n" +
                                         "\t\toption subnet-mask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                         "\t\toption domain-name-servers " + dtCPEStatic.Rows[i]["Dns"].ToString() + ";\n" +
                                         "\t\toption routers " + dtCPEStatic.Rows[i]["Router"].ToString() + ";\n" +
                                         "\t\toption broadcast-address " + dtCPEStatic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                         "\t}\n" +
                                         "\tgroup {\n" +
                                         "\t\tuse-host-decl-names on;\n" +
                                         txtmodem +
                                         "\t}\n";
                        }
                        #endregion
                        #region CableMode
                        for (int i = 0; i < dtPoolModem.Rows.Count; i++)
                        {
                            clsModem.PoolIp = dtPoolModem.Rows[i]["PoolIp"].ToString();
                            DataTable dtmodem   = clsModem.NW_Dhcp_Customer_GetbyPool_MySQL();
                            string    listmodem = "";
                            for (int j = 0; j < dtmodem.Rows.Count; j++)
                            {
                                string cm = dtmodem.Rows[j]["MacAddress"].ToString();
                                cm         = cm.Replace(":", "");
                                listmodem += "\t\t#  " + dtmodem.Rows[j]["IpAddress"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                             "\t\thost " + cm + " {\n" +
                                             "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacAddress"].ToString() + " ; \n" +
                                             "\t\t\tfixed-address " + dtmodem.Rows[j]["IpAddress"].ToString() + ";\n" +
                                             "\t\t\toption host-name \"cm" + cm + "\";\n" +
                                             "\t\t\tddns-hostname  \"cm" + cm + "\";\n" +
                                             "\t\t\toption bootfile-name \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                             "\t\t\tfilename \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                             "\t\t}\n";
                            }
                            PoolModem += "\tsubnet " + dtPoolModem.Rows[i]["PoolIp"].ToString() + " netmask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                         "\t\tauthoritative;\n" +
                                         "\t\toption subnet-mask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                         "\t\toption routers " + dtPoolModem.Rows[i]["Router"].ToString() + ";\n" +
                                         "\t\toption broadcast-address " + dtPoolModem.Rows[i]["Broadcast"].ToString() + ";\n" +
                                         "\t}\n" +
                                         "\tgroup {\n" +
                                         "\t\tuse-host-decl-names on;\n" +
                                         listmodem +
                                         "\t}\n";
                        }
                        #endregion

                        txt = txt.Replace("<_CPEDynamic>", CPEDynamic);
                        txt = txt.Replace("<_CPEStatic>", CPEStatic);
                        txt = txt.Replace("<_modemip>", PoolModem);

                        System.IO.File.WriteAllText(@"dhcpd.conf", txt);
                    }
                    else
                    {
                        MessageBox.Show("file dhcpd.conf.temp not found!");
                    }
                }
                MessageBox.Show("Hoàn thành tạo file !");
            }
            catch {
                MessageBox.Show("Lỗi tạo file..");
            }

            if (System.IO.File.Exists("dhcpd.conf"))
            {
                frmDHCPService_Template frm = new frmDHCPService_Template("dhcpd.conf");
                frm.ShowDialog();
            }
        }
Exemplo n.º 14
0
        private void btnCreateDHCPFile_Click(object sender, EventArgs e)
        {
            try
            {
                if (dt.Rows.Count > 0)
                {
                    if (System.IO.File.Exists(@"dhcpd.conf.temp"))
                    {
                        string txt = System.IO.File.ReadAllText(@"dhcpd.conf.temp");
                        string CPEDynamic = "";
                        string CPEStatic = "";
                        string PoolModem = "";
                        Class.NW_Dhcp_Ip clsIP = new Class.NW_Dhcp_Ip();
                        Class.NW_Dhcp_Customer clsModem = new Class.NW_Dhcp_Customer();
                        DataTable dtCPEDynamic = clsIP.NW_Dhcp_Ip_GetbyCPEDynamic_MySQL();
                        DataTable dtCPEStatic = clsIP.NW_Dhcp_Ip_GetbyCPEStatic_MySQL();
                        DataTable dtPoolModem = clsIP.NW_Dhcp_Ip_GetbyPoolModem_MySQL();
                        #region CPEDynamic
                        for (int i = 0; i < dtCPEDynamic.Rows.Count; i++)
                        {
                            CPEDynamic += "\tsubnet " + dtCPEDynamic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                            "\t\tauthoritative;\n" +
                                            "\t\toption subnet-mask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                            "\t\toption domain-name-servers " + dtCPEDynamic.Rows[i]["Dns"].ToString() + ";\n" +
                                            "\t\toption routers " + dtCPEDynamic.Rows[i]["Router"].ToString() + ";\n" +
                                            "\t\toption broadcast-address " + dtCPEDynamic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                            "\t\tpool {\n" +
                                                "\t\trange " + dtCPEDynamic.Rows[i]["RangeIP"].ToString() + ";\n" +
                                                "\t\t}\n" +
                                            "\t}\n" +
                                            "\tgroup {\n" +
                                                "\t\tuse-host-decl-names on;\n" +
                                            "\t}\n";
                        }
                        #endregion
                        #region CPEStatic
                        for (int i = 0; i < dtCPEStatic.Rows.Count; i++)
                        {
                            clsModem.PoolIp = dtCPEStatic.Rows[i]["PoolIp"].ToString();
                            DataTable dtmodem = clsModem.NW_Dhcp_Customer_GetbyPoolPublic_MySQL();
                            string txtmodem = "";
                            for (int j = 0; j < dtmodem.Rows.Count; j++)
                            {
                                string ipcpe = dtmodem.Rows[j]["IpPublic"].ToString();
                                ipcpe = ipcpe.Replace(":", "-");
                                string reIPcpe = dtmodem.Rows[j]["MacPc"].ToString().Replace(":", "");
                                txtmodem += "\t\t# PC an Modem " + dtmodem.Rows[j]["IpAddress"].ToString() + " " + dtmodem.Rows[j]["Note"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                            "\t\thost " + ipcpe + " {\n" +
                                                "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacPc"].ToString() + " ;\n" +
                                                "\t\t\tfixed-address " + dtmodem.Rows[j]["IpPublic"].ToString() + ";\n" +
                                                "\t\t\toption host-name 	\"mt" + reIPcpe + "\";\n" +
                                                "\t\t\tddns-hostname 	\"mt" + reIPcpe + "\";\n" +
                                            "\t\t}\n";
                            }

                            CPEStatic += "\tsubnet " + dtCPEStatic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                        "\t\tauthoritative;\n" +
                                        "\t\toption subnet-mask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                        "\t\toption domain-name-servers " + dtCPEStatic.Rows[i]["Dns"].ToString() + ";\n" +
                                        "\t\toption routers " + dtCPEStatic.Rows[i]["Router"].ToString() + ";\n" +
                                        "\t\toption broadcast-address " + dtCPEStatic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                        "\t}\n" +
                                        "\tgroup {\n" +
                                            "\t\tuse-host-decl-names on;\n" +
                                            txtmodem +
                                        "\t}\n";
                        }
                        #endregion
                        #region CableMode
                        for (int i = 0; i < dtPoolModem.Rows.Count; i++)
                        {
                            clsModem.PoolIp = dtPoolModem.Rows[i]["PoolIp"].ToString();
                            DataTable dtmodem = clsModem.NW_Dhcp_Customer_GetbyPool_MySQL();
                            string listmodem = "";
                            for (int j = 0; j < dtmodem.Rows.Count; j++)
                            {
                                string cm = dtmodem.Rows[j]["MacAddress"].ToString();
                                cm = cm.Replace(":", "");
                                listmodem += "\t\t#  " + dtmodem.Rows[j]["IpAddress"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                                "\t\thost " + cm + " {\n" +
                                                "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacAddress"].ToString() + " ; \n" +
                                                "\t\t\tfixed-address " + dtmodem.Rows[j]["IpAddress"].ToString() + ";\n" +
                                                "\t\t\toption host-name \"cm" + cm + "\";\n" +
                                                "\t\t\tddns-hostname  \"cm" + cm + "\";\n" +
                                                "\t\t\toption bootfile-name \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                                "\t\t\tfilename \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                                "\t\t}\n";
                            }
                            PoolModem += "\tsubnet " + dtPoolModem.Rows[i]["PoolIp"].ToString() + " netmask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                        "\t\tauthoritative;\n" +
                                        "\t\toption subnet-mask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                        "\t\toption routers " + dtPoolModem.Rows[i]["Router"].ToString() + ";\n" +
                                        "\t\toption broadcast-address " + dtPoolModem.Rows[i]["Broadcast"].ToString() + ";\n" +
                                        "\t}\n" +
                                        "\tgroup {\n" +
                                            "\t\tuse-host-decl-names on;\n" +
                                            listmodem +
                                         "\t}\n";

                        }
                        #endregion

                        txt = txt.Replace("<_CPEDynamic>", CPEDynamic);
                        txt = txt.Replace("<_CPEStatic>", CPEStatic);
                        txt = txt.Replace("<_modemip>", PoolModem);

                        System.IO.File.WriteAllText(@"dhcpd.conf", txt);
                    }
                    else
                    {
                        MessageBox.Show("file dhcpd.conf.temp not found!");
                    }
                }
                MessageBox.Show("Hoàn thành tạo file !");
            }
            catch {
                MessageBox.Show("Lỗi tạo file..");
            }

            if (System.IO.File.Exists("dhcpd.conf"))
            {
                frmDHCPService_Template frm = new frmDHCPService_Template("dhcpd.conf");
                frm.ShowDialog();
            }
        }
Exemplo n.º 15
0
 private void call_info(string Form_name, string code)
 {
     Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
     cls.IpAddress = code;
     DataTable dt = cls.NW_Dhcp_Customer_GetbyIp_MySQL();
     txtMacAddress.Text = dt.Rows[0]["MacAddress"].ToString();
     cboPoolIp.EditValue = dt.Rows[0]["PoolIp"].ToString();
     txtIpAddress.Text = dt.Rows[0]["IpAddress"].ToString();
     txtCustomerCode.Text = dt.Rows[0]["CustomerCode"].ToString();
     txtCustomerAddress.Text = dt.Rows[0]["CustomerAddress"].ToString();
     txtCustomerName.Text = dt.Rows[0]["CustomerName"].ToString();
     cboBootfile.Text = dt.Rows[0]["Bootfile"].ToString();
     txtLocation.Text = dt.Rows[0]["Location"].ToString();
     txtNote.Text = dt.Rows[0]["Note"].ToString();
     txtIpAddress.Enabled = false;
     cboPoolIp.Enabled = false;
 }
Exemplo n.º 16
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (dt.Rows.Count > 0)
            {
                Waiting.ShowWaitForm();
                Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
                string fail = "";
                for(int i=0;i<dt.Rows.Count;i++)
                {
                    Application.DoEvents();
                    Waiting.SetWaitFormDescription("Đang lưu ...("+(i+1).ToString()+")");
                    cls.IpAddress = dt.Rows[i]["IpAddress"].ToString();
                    cls.MacAddress = dt.Rows[i]["MacAddress"].ToString();
                    cls.MacAddress_CMTS = dt.Rows[i]["MacAddress_CMTS"].ToString();
                    cls.CustomerCode = dt.Rows[i]["CustomerCode"].ToString();
                    cls.CustomerName = dt.Rows[i]["CustomerName"].ToString();
                    cls.CustomerAddress = dt.Rows[i]["CustomerAddress"].ToString();
                    cls.PoolIp = dt.Rows[i]["PoolIp"].ToString();
                    cls.Bootfile = dt.Rows[i]["Bootfile"].ToString();
                    cls.IpPublic = dt.Rows[i]["IpPublic"].ToString();
                    cls.MacPc = dt.Rows[i]["MacPc"].ToString();
                    cls.PoolPublic = dt.Rows[i]["PoolPublic"].ToString();
                    cls.Location = dt.Rows[i]["Location"].ToString();
                    cls.Note = dt.Rows[i]["Note"].ToString();
                    //if (cls.IpAddress == "192.168.11.63")
                    //{
                    //    string degug = "";
                    //}
                    if (!cls.InsertMySQL()) // thay the import vao dl binh thuong thi impoort vao Mysql server co DHCP SV
                    {
                        fail += "\r\n" + dt.Rows[i]["IpAddress"].ToString();
                    }

                }
                Waiting.CloseWaitForm();
                //MessageBox.Show("Hoàn thành Insert !");
                //MessageBox.Show(fail);
            }
        }
Exemplo n.º 17
0
 private void btnDel_Click(object sender, EventArgs e)
 {
     if (Class.App.ConfirmDeletion() == DialogResult.No)
             return;
             Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
             string IP = "";
             IP = gridItemDetail.GetFocusedRowCellValue(colIpAddress).ToString();
             cls.IpAddress = IP;
             if (cls.NW_Dhcp_Customer_Delete_MySQL())
             {
                  Class.App.DeleteSuccessfully(IP);
                  NW_Dhcp_Customer_Getlist_MySQL();
             }
             else
             {
                 Class.App.DeleteNotSuccessfully();
             }
 }
Exemplo n.º 18
0
        private void btnDelIP_Click(object sender, EventArgs e)
        {
            Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
            cls.IpAddress = gridItemDetail.GetFocusedRowCellValue(colIpAddress).ToString();
            if (cls.NW_Dhcp_Customer_DeleteIPStatic_MySQL())
            {
                MessageBox.Show("Xóa IP Static thành công !");
                NW_Dhcp_Customer_Getlist_MySQL();
            }
            else
            {
                MessageBox.Show("Xóa IP Static thất bại !");

            }
        }
Exemplo n.º 19
0
 private void btnDeleteAll_Click(object sender, EventArgs e)
 {
     Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
        if (cls.NW_Dhcp_Customer_DeleteAll_MySQL())
        MessageBox.Show("Đã xóa xong! ");
 }
Exemplo n.º 20
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (cboPoolIp.EditValue == null)
            {
                Class.App.InputNotAccess();
                return;
            }
            if (txtMacAddress.Text.Length < 1)
            {
                Class.App.InputNotAccess();
                return;
            }

            if (txtIpAddress.Text.Length < 5)
            {
                MessageBox.Show("Địa chỉ IP Address chưa đúng định dạng, Vui lòng nhập lại.!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtMacAddress.Text.Length != 17)
            {
                MessageBox.Show("Địa chỉ Mac Address chưa đúng định dạng, Vui lòng nhập lại.!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
            cls.MacAddress = txtMacAddress.Text;
            string mac = txtMacAddress.Text;

            mac = mac.Replace(":", "");
            mac = mac.Insert(4, ".");
            mac = mac.Insert(9, ".");
            cls.MacAddress_CMTS = mac;
            cls.IpAddress       = txtIpAddress.Text;
            cls.PoolIp          = cboPoolIp.EditValue.ToString();
            cls.CustomerCode    = txtCustomerCode.Text;
            cls.CustomerName    = txtCustomerName.Text;
            cls.CustomerAddress = txtCustomerAddress.Text;
            cls.Bootfile        = cboBootfile.EditValue.ToString();
            cls.Location        = txtLocation.Text;
            cls.Note            = txtNote.Text;

            cls.IpPublic   = "";
            cls.PoolPublic = "";
            cls.MacPc      = "";
            if (txtIpAddress.Enabled)
            {
                if (cls.InsertMySQL())
                {
                    Class.App.SaveSuccessfully();
                    add_edit = true;
                }
                else
                {
                    Class.App.SaveNotSuccessfully();
                }
            }
            else
            {
                if (cls.UpdateMySQL())
                {
                    Class.App.SaveSuccessfully();
                    add_edit = true;
                }
                else
                {
                    Class.App.SaveNotSuccessfully();
                }
            }
            this.Close();
        }
Exemplo n.º 21
0
        private void txtMacAddress_Validated(object sender, EventArgs e)
        {
            txtMacAddress.Text = txtMacAddress.Text.Replace("-", ":").ToLower();
            string input = txtMacAddress.Text;
               // input = input.Replace(" ", "").Replace(":", "").Replace("-", "");

            Regex r = new Regex("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$");

            if (!r.IsMatch(input))
            {
                MessageBox.Show(" Mac Address không hợp lệ ! ");
                txtMacAddress.Focus();
            }
            if (txtIpAddress.Enabled)
            {
                Class.NW_Dhcp_Customer clscus = new Class.NW_Dhcp_Customer();
                clscus.MacAddress = txtMacAddress.Text;
                DataTable dt = clscus.NW_Dhcp_Customer_GetbyMacaddress_MySQL();
                if (dt.Rows.Count > 0)
                {
                    MessageBox.Show(" Mac Address đã có, vui lòng chọn mac khác ! ");
                    txtMacAddress.Focus();
                }
            }
            else
            {
                // truong hop sua nhung co roi cung ko dc update
                Class.NW_Dhcp_Customer clscus = new Class.NW_Dhcp_Customer();
                clscus.MacAddress = txtMacAddress.Text;
                clscus.IpAddress=txtIpAddress.Text;
                DataTable dt = clscus.NW_Dhcp_Customer_GetbyMacaddress_MySQL();
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["IpAddress"].ToString() != clscus.IpAddress)
                    {
                        MessageBox.Show(" Mac Address đã có, vui lòng chọn mac khác ! ");
                        txtMacAddress.Focus();
                    }
                }

            }
        }
Exemplo n.º 22
0
        public void Start()
        {
            try
            {
                IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
               // IPAddress ipAddr = ipHost.AddressList[3];
                //string ip = "";
                //for (int i = 1; i < ipHost.AddressList.Length; i++)
                //{
                //    ip = ipHost.AddressList[i].ToString();
                    server.Prefixes.Add("http://" + "101.99.28.148" + ":1111/");
                //}

                // server.Start();
                try
                {
                    server.Start(); //Throws Exception
                }
                catch (HttpListenerException ex)
                {
                    if (ex.Message.Contains("Access is denied"))
                    {
                        return;
                    }
                    else
                    {
                        throw;
                    }
                }
                Console.WriteLine("Listening...");

                while (true)
                {
                    HttpListenerContext context = server.GetContext();
                    HttpListenerResponse response = context.Response;

                    string page = context.Request.Url.ToString();

                    //page = context.Request.Url.LocalPath; ;
                    //   if (page == string.Empty)

                    if (page.Contains("dhcprestart.html"))
                    {
                        string msg = "";
                        // tao file conf
                        #region Tao file config
                        try
                        {
                            Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
                             DataTable dt = cls.NW_Dhcp_Customer_Getlist();
                            if (dt.Rows.Count > 0)
                            {
                                if (System.IO.File.Exists(@"dhcpd.conf.temp"))
                                {
                                    string txt = System.IO.File.ReadAllText(@"dhcpd.conf.temp");
                                    string CPEDynamic = "";
                                    string CPEStatic = "";
                                    string PoolModem = "";
                                    Class.NW_Dhcp_Ip clsIP = new Class.NW_Dhcp_Ip();
                                    Class.NW_Dhcp_Customer clsModem = new Class.NW_Dhcp_Customer();
                                    DataTable dtCPEDynamic = clsIP.NW_Dhcp_Ip_GetbyCPEDynamic();
                                    DataTable dtCPEStatic = clsIP.NW_Dhcp_Ip_GetbyCPEStatic();
                                    DataTable dtPoolModem = clsIP.NW_Dhcp_Ip_GetbyPoolModem();
                                    #region CPEDynamic
                                    for (int i = 0; i < dtCPEDynamic.Rows.Count; i++)
                                    {
                                        CPEDynamic += "\tsubnet " + dtCPEDynamic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                                        "\t\tauthoritative;\n" +
                                                        "\t\toption subnet-mask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                                        "\t\toption domain-name-servers " + dtCPEDynamic.Rows[i]["Dns"].ToString() + ";\n" +
                                                        "\t\toption routers " + dtCPEDynamic.Rows[i]["Router"].ToString() + ";\n" +
                                                        "\t\toption broadcast-address " + dtCPEDynamic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                                        "\t\tpool {\n" +
                                                            "\t\trange " + dtCPEDynamic.Rows[i]["Range"].ToString() + ";\n" +
                                                            "\t\t}\n" +
                                                        "\t}\n" +
                                                        "\tgroup {\n" +
                                                            "\t\tuse-host-decl-names on;\n" +
                                                        "\t}\n";
                                    }
                                    #endregion
                                    #region CPEStatic
                                    for (int i = 0; i < dtCPEStatic.Rows.Count; i++)
                                    {
                                        clsModem.PoolIp = dtCPEStatic.Rows[i]["PoolIp"].ToString();
                                        DataTable dtmodem = clsModem.NW_Dhcp_Customer_GetbyPoolPublic();
                                        string txtmodem = "";
                                        for (int j = 0; j < dtmodem.Rows.Count; j++)
                                        {
                                            string ipcpe = dtmodem.Rows[j]["IpPublic"].ToString();
                                            ipcpe = ipcpe.Replace(":", "-");
                                            string reIPcpe = dtmodem.Rows[j]["MacPc"].ToString().Replace(":", "");
                                            txtmodem += "\t\t# PC an Modem " + dtmodem.Rows[j]["IpAddress"].ToString() + " " + dtmodem.Rows[j]["Note"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                                        "\t\thost " + ipcpe + " {\n" +
                                                            "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacPc"].ToString() + " ;\n" +
                                                            "\t\t\tfixed-address " + dtmodem.Rows[j]["IpPublic"].ToString() + ";\n" +
                                                            "\t\t\toption host-name 	\"mt" + reIPcpe + "\";\n" +
                                                            "\t\t\tddns-hostname 	\"mt" + reIPcpe + "\";\n" +
                                                        "\t\t}\n";
                                        }

                                        CPEStatic += "\tsubnet " + dtCPEStatic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                                    "\t\tauthoritative;\n" +
                                                    "\t\toption subnet-mask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                                    "\t\toption domain-name-servers " + dtCPEStatic.Rows[i]["Dns"].ToString() + ";\n" +
                                                    "\t\toption routers " + dtCPEStatic.Rows[i]["Router"].ToString() + ";\n" +
                                                    "\t\toption broadcast-address " + dtCPEStatic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                                    "\t}\n" +
                                                    "\tgroup {\n" +
                                                        "\t\tuse-host-decl-names on;\n" +
                                                        txtmodem +
                                                    "\t}\n";
                                    }
                                    #endregion
                                    #region CableMode
                                    for (int i = 0; i < dtPoolModem.Rows.Count; i++)
                                    {
                                        clsModem.PoolIp = dtPoolModem.Rows[i]["PoolIp"].ToString();
                                        DataTable dtmodem = clsModem.NW_Dhcp_Customer_GetbyPool();
                                        string listmodem = "";
                                        for (int j = 0; j < dtmodem.Rows.Count; j++)
                                        {
                                            string cm = dtmodem.Rows[j]["MacAddress"].ToString();
                                            cm = cm.Replace(":", "");
                                            listmodem += "\t\t#  " + dtmodem.Rows[j]["IpAddress"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                                            "\t\thost " + cm + " {\n" +
                                                            "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacAddress"].ToString() + " ; \n" +
                                                            "\t\t\tfixed-address " + dtmodem.Rows[j]["IpAddress"].ToString() + ";\n" +
                                                            "\t\t\toption host-name \"cm" + cm + "\";\n" +
                                                            "\t\t\tddns-hostname  \"cm" + cm + "\";\n" +
                                                            "\t\t\toption bootfile-name \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                                            "\t\t\tfilename \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                                            "\t\t}\n";
                                        }
                                        PoolModem += "\tsubnet " + dtPoolModem.Rows[i]["PoolIp"].ToString() + " netmask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                                    "\t\tauthoritative;\n" +
                                                    "\t\toption subnet-mask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                                    "\t\toption routers " + dtPoolModem.Rows[i]["Router"].ToString() + ";\n" +
                                                    "\t\toption broadcast-address " + dtPoolModem.Rows[i]["Broadcast"].ToString() + ";\n" +
                                                    "\t}\n" +
                                                    "\tgroup {\n" +
                                                        "\t\tuse-host-decl-names on;\n" +
                                                        listmodem +
                                                     "\t}\n";

                                    }
                                    #endregion

                                    txt = txt.Replace("<_CPEDynamic>", CPEDynamic);
                                    txt = txt.Replace("<_CPEStatic>", CPEStatic);
                                    txt = txt.Replace("<_modemip>", PoolModem);

                                    System.IO.File.WriteAllText(@"dhcpd.conf", txt);
                                }
                                else
                                {
                                    msg="file dhcpd.conf.temp not found!";
                                }
                            }
                            msg = "Create file success!";
                        }
                        catch
                        {
                            msg = "Fail create to file..";
                        }
                        #endregion
                        #region UploadtoServer
                        if (msg == "Create file success!")
                        {
                            msg += "\r\nTranfer file to SERVER ";
                            Class.App.uploadFile("ftp://101.99.28.152/test/", Application.StartupPath + "/dhcpd.conf", "administrator", "831031");
                            try
                            {
                                msg += "Ok";
                            }
                            catch {
                                msg += "Fail";
                            }
                        }
                        #endregion

                        //write respones
                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();

                    }
                    else
                    {
                        string msg = "Access Deny !";

                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                    }

                    context.Response.Close();
                }
            }
            catch {
                Stop();
                Start();
            }
        }
Exemplo n.º 23
0
        public void Start()
        {
            try
            {
                IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
                // IPAddress ipAddr = ipHost.AddressList[3];
                //string ip = "";
                //for (int i = 1; i < ipHost.AddressList.Length; i++)
                //{
                //    ip = ipHost.AddressList[i].ToString();
                server.Prefixes.Add("http://" + "101.99.28.148" + ":1111/");
                //}

                // server.Start();
                try
                {
                    server.Start(); //Throws Exception
                }
                catch (HttpListenerException ex)
                {
                    if (ex.Message.Contains("Access is denied"))
                    {
                        return;
                    }
                    else
                    {
                        throw;
                    }
                }
                Console.WriteLine("Listening...");

                while (true)
                {
                    HttpListenerContext  context  = server.GetContext();
                    HttpListenerResponse response = context.Response;

                    string page = context.Request.Url.ToString();

                    //page = context.Request.Url.LocalPath; ;
                    //   if (page == string.Empty)

                    if (page.Contains("dhcprestart.html"))
                    {
                        string msg = "";
                        // tao file conf
                        #region Tao file config
                        try
                        {
                            Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
                            DataTable dt = cls.NW_Dhcp_Customer_Getlist();
                            if (dt.Rows.Count > 0)
                            {
                                if (System.IO.File.Exists(@"dhcpd.conf.temp"))
                                {
                                    string                 txt          = System.IO.File.ReadAllText(@"dhcpd.conf.temp");
                                    string                 CPEDynamic   = "";
                                    string                 CPEStatic    = "";
                                    string                 PoolModem    = "";
                                    Class.NW_Dhcp_Ip       clsIP        = new Class.NW_Dhcp_Ip();
                                    Class.NW_Dhcp_Customer clsModem     = new Class.NW_Dhcp_Customer();
                                    DataTable              dtCPEDynamic = clsIP.NW_Dhcp_Ip_GetbyCPEDynamic();
                                    DataTable              dtCPEStatic  = clsIP.NW_Dhcp_Ip_GetbyCPEStatic();
                                    DataTable              dtPoolModem  = clsIP.NW_Dhcp_Ip_GetbyPoolModem();
                                    #region CPEDynamic
                                    for (int i = 0; i < dtCPEDynamic.Rows.Count; i++)
                                    {
                                        CPEDynamic += "\tsubnet " + dtCPEDynamic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                                      "\t\tauthoritative;\n" +
                                                      "\t\toption subnet-mask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                                      "\t\toption domain-name-servers " + dtCPEDynamic.Rows[i]["Dns"].ToString() + ";\n" +
                                                      "\t\toption routers " + dtCPEDynamic.Rows[i]["Router"].ToString() + ";\n" +
                                                      "\t\toption broadcast-address " + dtCPEDynamic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                                      "\t\tpool {\n" +
                                                      "\t\trange " + dtCPEDynamic.Rows[i]["Range"].ToString() + ";\n" +
                                                      "\t\t}\n" +
                                                      "\t}\n" +
                                                      "\tgroup {\n" +
                                                      "\t\tuse-host-decl-names on;\n" +
                                                      "\t}\n";
                                    }
                                    #endregion
                                    #region CPEStatic
                                    for (int i = 0; i < dtCPEStatic.Rows.Count; i++)
                                    {
                                        clsModem.PoolIp = dtCPEStatic.Rows[i]["PoolIp"].ToString();
                                        DataTable dtmodem  = clsModem.NW_Dhcp_Customer_GetbyPoolPublic();
                                        string    txtmodem = "";
                                        for (int j = 0; j < dtmodem.Rows.Count; j++)
                                        {
                                            string ipcpe = dtmodem.Rows[j]["IpPublic"].ToString();
                                            ipcpe = ipcpe.Replace(":", "-");
                                            string reIPcpe = dtmodem.Rows[j]["MacPc"].ToString().Replace(":", "");
                                            txtmodem += "\t\t# PC an Modem " + dtmodem.Rows[j]["IpAddress"].ToString() + " " + dtmodem.Rows[j]["Note"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                                        "\t\thost " + ipcpe + " {\n" +
                                                        "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacPc"].ToString() + " ;\n" +
                                                        "\t\t\tfixed-address " + dtmodem.Rows[j]["IpPublic"].ToString() + ";\n" +
                                                        "\t\t\toption host-name 	\"mt"+ reIPcpe + "\";\n" +
                                                        "\t\t\tddns-hostname 	\"mt"+ reIPcpe + "\";\n" +
                                                        "\t\t}\n";
                                        }

                                        CPEStatic += "\tsubnet " + dtCPEStatic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                                     "\t\tauthoritative;\n" +
                                                     "\t\toption subnet-mask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                                     "\t\toption domain-name-servers " + dtCPEStatic.Rows[i]["Dns"].ToString() + ";\n" +
                                                     "\t\toption routers " + dtCPEStatic.Rows[i]["Router"].ToString() + ";\n" +
                                                     "\t\toption broadcast-address " + dtCPEStatic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                                     "\t}\n" +
                                                     "\tgroup {\n" +
                                                     "\t\tuse-host-decl-names on;\n" +
                                                     txtmodem +
                                                     "\t}\n";
                                    }
                                    #endregion
                                    #region CableMode
                                    for (int i = 0; i < dtPoolModem.Rows.Count; i++)
                                    {
                                        clsModem.PoolIp = dtPoolModem.Rows[i]["PoolIp"].ToString();
                                        DataTable dtmodem   = clsModem.NW_Dhcp_Customer_GetbyPool();
                                        string    listmodem = "";
                                        for (int j = 0; j < dtmodem.Rows.Count; j++)
                                        {
                                            string cm = dtmodem.Rows[j]["MacAddress"].ToString();
                                            cm         = cm.Replace(":", "");
                                            listmodem += "\t\t#  " + dtmodem.Rows[j]["IpAddress"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                                         "\t\thost " + cm + " {\n" +
                                                         "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacAddress"].ToString() + " ; \n" +
                                                         "\t\t\tfixed-address " + dtmodem.Rows[j]["IpAddress"].ToString() + ";\n" +
                                                         "\t\t\toption host-name \"cm" + cm + "\";\n" +
                                                         "\t\t\tddns-hostname  \"cm" + cm + "\";\n" +
                                                         "\t\t\toption bootfile-name \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                                         "\t\t\tfilename \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                                         "\t\t}\n";
                                        }
                                        PoolModem += "\tsubnet " + dtPoolModem.Rows[i]["PoolIp"].ToString() + " netmask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                                     "\t\tauthoritative;\n" +
                                                     "\t\toption subnet-mask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                                     "\t\toption routers " + dtPoolModem.Rows[i]["Router"].ToString() + ";\n" +
                                                     "\t\toption broadcast-address " + dtPoolModem.Rows[i]["Broadcast"].ToString() + ";\n" +
                                                     "\t}\n" +
                                                     "\tgroup {\n" +
                                                     "\t\tuse-host-decl-names on;\n" +
                                                     listmodem +
                                                     "\t}\n";
                                    }
                                    #endregion

                                    txt = txt.Replace("<_CPEDynamic>", CPEDynamic);
                                    txt = txt.Replace("<_CPEStatic>", CPEStatic);
                                    txt = txt.Replace("<_modemip>", PoolModem);

                                    System.IO.File.WriteAllText(@"dhcpd.conf", txt);
                                }
                                else
                                {
                                    msg = "file dhcpd.conf.temp not found!";
                                }
                            }
                            msg = "Create file success!";
                        }
                        catch
                        {
                            msg = "Fail create to file..";
                        }
                        #endregion
                        #region UploadtoServer
                        if (msg == "Create file success!")
                        {
                            msg += "\r\nTranfer file to SERVER ";
                            Class.App.uploadFile("ftp://101.99.28.152/test/", Application.StartupPath + "/dhcpd.conf", "administrator", "831031");
                            try
                            {
                                msg += "Ok";
                            }
                            catch {
                                msg += "Fail";
                            }
                        }
                        #endregion

                        //write respones
                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                    }
                    else
                    {
                        string msg = "Access Deny !";

                        byte[] buffer = Encoding.UTF8.GetBytes(msg);

                        response.ContentLength64 = buffer.Length;
                        Stream st = response.OutputStream;
                        st.Write(buffer, 0, buffer.Length);
                        st.Close();
                    }

                    context.Response.Close();
                }
            }
            catch {
                Stop();
                Start();
            }
        }
Exemplo n.º 24
0
        private void btnUpdateNew_Click(object sender, EventArgs e)
        {
            if (cboPoolIp.EditValue == null)
            {
                Class.App.InputNotAccess();
                return;
            }
            if (txtMacAddress.Text.Length < 1)
            {
                Class.App.InputNotAccess();
                return;
            }
            if (txtIpAddress.Text.Length < 5)
            {
                MessageBox.Show("Địa chỉ IP Address chưa đúng định dạng, Vui lòng nhập lại.!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (txtMacAddress.Text.Length != 17)
            {
                MessageBox.Show("Địa chỉ Mac Address chưa đúng định dạng, Vui lòng nhập lại.!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer();
            cls.MacAddress = txtMacAddress.Text;
            string mac = txtMacAddress.Text;
            mac = mac.Replace(":", "");
            mac = mac.Insert(4, ".");
            mac = mac.Insert(9, ".");
            cls.MacAddress_CMTS = mac;
            cls.IpAddress = txtIpAddress.Text;
            cls.PoolIp = cboPoolIp.EditValue.ToString();
            cls.CustomerCode = txtCustomerCode.Text;
            cls.CustomerName = txtCustomerName.Text;
            cls.CustomerAddress = txtCustomerAddress.Text;
            cls.Bootfile = cboBootfile.EditValue.ToString();
            cls.Location = txtLocation.Text;
            cls.Note = txtNote.Text;

            cls.IpPublic = "";
            cls.PoolPublic = "";
            cls.MacPc = "";
            if (txtIpAddress.Enabled)
            {
                if (cls.InsertMySQL())
                {
                    Class.App.SaveSuccessfully();
                    add_edit = true;
                }
                else
                {
                    Class.App.SaveNotSuccessfully();
                }
            }
            else
            {
                if (cls.UpdateMySQL())
                {
                    Class.App.SaveSuccessfully();
                    add_edit = true;
                }
                else
                {
                    Class.App.SaveNotSuccessfully();
                }
            }

            txtIpAddress.Enabled = true;
            cboPoolIp.Enabled = true;
            call_Code_New();
            //NW_Dhcp_Ip_GetbyPoolModem();
            NW_Dhcp_Ip_GetbyPoolModem_MySQL();
        }