示例#1
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();
            }
        }
示例#2
0
        private void btnDHCPTemplate_Click(object sender, EventArgs e)
        {
            frmDHCPService_Template frm = new frmDHCPService_Template("dhcpd.conf.temp");

            frm.ShowDialog();
        }
示例#3
0
 private void btnDHCPTemplate_Click(object sender, EventArgs e)
 {
     frmDHCPService_Template frm = new frmDHCPService_Template("dhcpd.conf.temp");
     frm.ShowDialog();
 }
示例#4
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();
            }
        }