Example #1
0
        public override void OnRecoveryLoad(XmlElement root)
        {
            XmlElement nodeDns = UtilsXml.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 = UtilsXml.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);
        }
Example #2
0
        public override bool OnDnsSwitchDo(IpAddresses 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 currentStr = SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-getdnsservers", SystemShell.EscapeInsideQuote(i2) });

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

                    if (dns.Equals(current) == false)
                    {
                        DnsSwitchEntry e = new DnsSwitchEntry();
                        e.Name = i2;
                        e.Dns  = current.Addresses;
                        m_listDnsSwitch.Add(e);

                        SystemShell s = new SystemShell();
                        s.Path = LocateExecutable("networksetup");
                        s.Arguments.Add("-setdnsservers");
                        s.Arguments.Add(SystemShell.EscapeInsideQuote(i2));
                        if (dns.IPs.Count == 0)
                        {
                            s.Arguments.Add("empty");
                        }
                        else
                        {
                            foreach (IpAddress ip in dns.IPs)
                            {
                                s.Arguments.Add(ip.Address);
                            }
                        }
                        s.Run();

                        Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.NetworkAdapterDnsDone, i2, ((current.Count == 0) ? "Automatic" : current.Addresses), dns.Addresses));
                    }
                }

                Recovery.Save();
            }

            base.OnDnsSwitchDo(dns);

            return(true);
        }
Example #3
0
        public override bool OnDnsSwitchDo(ConnectionActive connectionActive, IpAddresses dns)
        {
            string mode = Engine.Instance.Storage.GetLower("dns.mode");

            if (mode == "auto")
            {
                string result = Engine.Instance.Elevated.DoCommandSync("dns-switch-do", "dns", dns.ToString());
                if (result != "")
                {
                    foreach (string resultItem in result.Split('\n'))
                    {
                        string[] fields = resultItem.Split(';');
                        if (fields.Length != 3)
                        {
                            continue;
                        }
                        if (fields[0] == "SwitchDNS")
                        {
                            string      interfaceName = fields[1];
                            IpAddresses oldIPs        = new IpAddresses(fields[2]);

                            DnsSwitchEntry e = new DnsSwitchEntry();
                            e.Name = interfaceName;
                            e.Dns  = oldIPs.Addresses;
                            m_listDnsSwitch.Add(e);

                            Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("OsMacNetworkAdapterDnsDone", interfaceName, ((oldIPs.Count == 0) ? "Automatic" : oldIPs.Addresses), dns.Addresses));
                        }
                    }
                }

                Recovery.Save();
            }

            base.OnDnsSwitchDo(connectionActive, dns);

            return(true);
        }