예제 #1
0
        public override void OnRecoveryLoad(XmlElement root)
        {
            XmlElement nodeDns = Utils.XmlGetFirstElementByTagName(root, "DnsSwitch");

            if (nodeDns != null)
            {
                foreach (XmlElement nodeEntry in nodeDns.ChildNodes)
                {
                    DnsSwitchEntry entry = new DnsSwitchEntry();
                    entry.ReadXML(nodeEntry);
                    m_listDnsSwitch.Add(entry);
                }
            }

            XmlElement nodeIpV6 = Utils.XmlGetFirstElementByTagName(root, "IpV6");

            if (nodeIpV6 != null)
            {
                foreach (XmlElement nodeEntry in nodeIpV6.ChildNodes)
                {
                    IpV6ModeEntry entry = new IpV6ModeEntry();
                    entry.ReadXML(nodeEntry);
                    m_listIpV6Mode.Add(entry);
                }
            }

            base.OnRecoveryLoad(root);
        }
예제 #2
0
        public override bool OnDnsSwitchDo(string dns)
        {
            string mode = Engine.Instance.Storage.GetLower("dns.mode");

            if (mode == "auto")
            {
                string[] interfaces = GetInterfaces();
                foreach (string i in interfaces)
                {
                    string i2 = i.Trim();

                    string current = ShellCmd("networksetup -getdnsservers \"" + i2 + "\"");

                    // v2
                    List <string> ips = new List <string>();
                    foreach (string line in current.Split('\n'))
                    {
                        string ip = line.Trim();
                        if (IpAddress.IsIP(ip))
                        {
                            ips.Add(ip);
                        }
                    }

                    if (ips.Count != 0)
                    {
                        current = String.Join(",", ips.ToArray());
                    }
                    else
                    {
                        current = "";
                    }
                    if (current != dns)
                    {
                        // Switch
                        Engine.Instance.Logs.Log(LogType.Verbose, Messages.Format(Messages.NetworkAdapterDnsDone, i2, ((current == "") ? "Automatic" : current), dns));

                        DnsSwitchEntry e = new DnsSwitchEntry();
                        e.Name = i2;
                        e.Dns  = current;
                        m_listDnsSwitch.Add(e);

                        string dns2 = dns.Replace(",", "\" \"");
                        ShellCmd("networksetup -setdnsservers \"" + i2 + "\" \"" + dns2 + "\"");
                    }
                }

                Recovery.Save();
            }

            base.OnDnsSwitchDo(dns);

            return(true);
        }
예제 #3
0
        public override void OnRecoveryLoad(XmlElement root)
        {
            XmlElement nodeDns = Utils.XmlGetFirstElementByTagName(root, "DnsSwitch");
            if (nodeDns != null)
            {
                foreach (XmlElement nodeEntry in nodeDns.ChildNodes)
                {
                    DnsSwitchEntry entry = new DnsSwitchEntry();
                    entry.ReadXML(nodeEntry);
                    m_listDnsSwitch.Add(entry);
                }
            }

            XmlElement nodeIpV6 = Utils.XmlGetFirstElementByTagName(root, "IpV6");
            if (nodeIpV6 != null)
            {
                foreach (XmlElement nodeEntry in nodeIpV6.ChildNodes)
                {
                    IpV6ModeEntry entry = new IpV6ModeEntry();
                    entry.ReadXML(nodeEntry);
                    m_listIpV6Mode.Add(entry);
                }
            }

            base.OnRecoveryLoad(root);
        }
예제 #4
0
        public override bool OnDnsSwitchDo(string dns)
        {
            string mode = Engine.Instance.Storage.GetLower("dns.mode");

            if (mode == "auto")
            {
                string[] interfaces = GetInterfaces();
                foreach (string i in interfaces)
                {
                    string i2 = i.Trim();

                    string current = ShellCmd("networksetup -getdnsservers \"" + i2 + "\"");

                    // v2
                    List<string> ips = new List<string>();
                    foreach(string line in current.Split('\n'))
                    {
                        string ip = line.Trim();
                        if (IpAddress.IsIP(ip))
                            ips.Add(ip);
                    }

                    if (ips.Count != 0)
                        current = String.Join(",", ips.ToArray());
                    else
                        current = "";
                    if (current != dns)
                    {
                        // Switch
                        Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.NetworkAdapterDnsDone, i2, ((current == "") ? "Automatic" : current), dns));

                        DnsSwitchEntry e = new DnsSwitchEntry();
                        e.Name = i2;
                        e.Dns = current;
                        m_listDnsSwitch.Add(e);

                        string dns2 = dns.Replace(",", "\" \"");
                        ShellCmd("networksetup -setdnsservers \"" + i2 + "\" \"" + dns2 + "\"");
                    }
                }

                Recovery.Save ();
            }

            base.OnDnsSwitchDo(dns);

            return true;
        }