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

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

            OnDnsSwitchRestore();
        }
Beispiel #2
0
        public override void OnDnsSwitchDo(string dns)
        {
            base.OnDnsSwitchDo(dns);

            string mode = Engine.Instance.Storage.Get("advanced.dns.mode").ToLowerInvariant();

            if (mode == "auto")
            {
                string[] interfaces = ShellCmd("networksetup -listallnetworkservices | grep -v denotes").Split('\n');
                foreach (string i in interfaces)
                {
                    string i2 = i.Trim();

                    string current = ShellCmd("networksetup -getdnsservers \"" + i2 + "\"");
                    current = current.Replace("\n", ";");
                    if (current.StartsWith("There aren't any DNS Servers set on "))
                    {
                        current = "0.0.0.0";
                    }
                    if (Utils.IsIP(current))
                    {
                        if (current != dns)
                        {
                            // Switch
                            Engine.Instance.Log(Engine.LogType.Info, Messages.Format(Messages.NetworkAdapterDnsDone, i2));

                            DnsSwitchInterface e = new DnsSwitchInterface();
                            e.Name = i2;
                            e.Dns  = current;
                            ListDnsSwitchInterfaces.Add(e);

                            ShellCmd("networksetup -setdnsservers \"" + i2 + "\" \"" + dns + "\"");
                        }
                    }
                    else
                    {
                        Engine.Instance.Log(Engine.LogType.Verbose, "Unknown networksetup output: '" + current + "'");
                    }
                }

                Recovery.Save();
            }
        }