示例#1
0
        public override IpAddresses DetectDNS()
        {
            IpAddresses list = new IpAddresses();

            // Method1: Don't return DHCP DNS
            string networksetupPath = LocateExecutable("networksetup");

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

                    string current = SystemShell.Shell(networksetupPath, new string[] { "-getdnsservers", SystemShell.EscapeInsideQuote(i2) });

                    foreach (string line in current.Split('\n'))
                    {
                        string field = line.Trim();
                        list.Add(field);
                    }
                }
            }

            // Method2 - More info about DHCP DNS
            string scutilPath = LocateExecutable("scutil");

            if (scutilPath != "")
            {
                string scutilOut             = SystemShell.Shell1(scutilPath, "--dns");
                List <List <string> > result = UtilsString.RegExMatchMulti(scutilOut.Replace(" ", ""), "nameserver\\[[0-9]+\\]:([0-9:\\.]+)");
                foreach (List <string> match in result)
                {
                    foreach (string field in match)
                    {
                        list.Add(field);
                    }
                }
            }

            // Method3 - Compatibility
            if (FileExists("/etc/resolv.conf"))
            {
                string o = FileContentsReadText("/etc/resolv.conf");
                foreach (string line in o.Split('\n'))
                {
                    if (line.Trim().StartsWith("#"))
                    {
                        continue;
                    }
                    if (line.Trim().StartsWith("nameserver"))
                    {
                        string field = line.Substring(11).Trim();
                        list.Add(field);
                    }
                }
            }

            return(list);
        }
示例#2
0
        public override bool OnIpV6Restore()
        {
            foreach (IpV6ModeEntry entry in m_listIpV6Mode)
            {
                if (entry.Mode == "Off")
                {
                    SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-setv6off", SystemShell.EscapeInsideQuote(entry.Interface) });
                }
                else if (entry.Mode == "Automatic")
                {
                    SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-setv6automatic", SystemShell.EscapeInsideQuote(entry.Interface) });
                }
                else if (entry.Mode == "LinkLocal")
                {
                    SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-setv6LinkLocal", SystemShell.EscapeInsideQuote(entry.Interface) });
                }
                else if (entry.Mode == "Manual")
                {
                    SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-setv6manual", SystemShell.EscapeInsideQuote(entry.Interface), entry.Address, entry.PrefixLength, entry.Router });
                }

                Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.NetworkAdapterIpV6Restored, entry.Interface));
            }

            m_listIpV6Mode.Clear();

            Recovery.Save();

            base.OnIpV6Restore();

            return(true);
        }
示例#3
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);
        }
示例#4
0
        public override bool IsAdmin()
        {
            // With root privileges by RootLauncher.cs, Environment.UserName still return the normal username, 'whoami' return 'root'.
            string u = SystemShell.Shell("/usr/bin/whoami", new string[] { }).ToLowerInvariant().Trim();

            //return true; // Uncomment for debugging
            return(u == "root");
        }
示例#5
0
        public override void OnJsonNetworkInfo(Json jNetworkInfo)
        {
            // Step1: Set IPv6 support to true by default.
            // From base virtual, always 'false'. Missing Mono implementation?
            // After for interfaces listed by 'networksetup -listallhardwareports' we detect specific support.
            foreach (Json jNetworkInterface in jNetworkInfo["interfaces"].Json.GetArray())
            {
                jNetworkInterface["support_ipv6"].Value = true;
            }

            // Step2: Query 'networksetup -listallhardwareports' to obtain a more accurate device friendly names.
            string networksetupPath = LocateExecutable("networksetup");

            if (networksetupPath != "")
            {
                string nsOutput = SystemShell.Shell1(networksetupPath, "-listallhardwareports");
                string lastName = "";
                foreach (string line in nsOutput.Split('\n'))
                {
                    if (line.StartsWith("Hardware Port: ", StringComparison.InvariantCulture))
                    {
                        lastName = line.Substring(15).Trim();
                    }
                    if (line.StartsWith("Device:", StringComparison.InvariantCulture))
                    {
                        string deviceId = line.Substring(7).Trim();
                        foreach (Json jNetworkInterface in jNetworkInfo["interfaces"].Json.GetArray())
                        {
                            if (jNetworkInterface["id"].Value as string == deviceId)
                            {
                                // Set friendly name
                                jNetworkInterface["friendly"].Value = lastName;

                                // Detect IPv6 support
                                string getInfo = SystemShell.Shell(LocateExecutable("networksetup"), new string[] { "-getinfo", SystemShell.EscapeInsideQuote(lastName) });

                                string mode = getInfo.RegExMatchOne("^IPv6: (.*?)$").Trim();

                                if (mode == "Off")
                                {
                                    jNetworkInterface["support_ipv6"].Value = false;
                                }
                                else
                                {
                                    jNetworkInterface["support_ipv6"].Value = true;
                                }

                                break;
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        public override void OnInit(bool cli)
        {
            base.OnInit(cli);

            if (cli)
            {
                NSApplication.Init();                 // Requested in CLI edition to call NSPipe, NSTask etc.
            }
            m_version      = SystemShell.Shell("/usr/bin/uname", new string[] { "-a" }).Trim();
            m_architecture = NormalizeArchitecture(SystemShell.Shell("/usr/bin/uname", new string[] { "-m" }).Trim());

            NativeMethods.eddie_signal((int)NativeMethods.Signum.SIGINT, SignalCallback);
            NativeMethods.eddie_signal((int)NativeMethods.Signum.SIGTERM, SignalCallback);
            NativeMethods.eddie_signal((int)NativeMethods.Signum.SIGUSR1, SignalCallback);
            NativeMethods.eddie_signal((int)NativeMethods.Signum.SIGUSR2, SignalCallback);
        }
示例#7
0
        public override void OnInit(bool cli)
        {
            base.OnInit(cli);

            if (cli)
            {
                NSApplication.Init();                 // Requested in CLI edition to call NSPipe, NSTask etc.
            }
            m_version      = SystemShell.Shell("/usr/bin/uname", new string[] { "-a" }).Trim();
            m_architecture = NormalizeArchitecture(SystemShell.Shell("/usr/bin/uname", new string[] { "-m" }).Trim());


            Native.eddie_signal((int)Native.Signum.SIGINT, SignalCallback);
            Native.eddie_signal((int)Native.Signum.SIGTERM, SignalCallback);
            Native.eddie_signal((int)Native.Signum.SIGUSR1, SignalCallback);
            Native.eddie_signal((int)Native.Signum.SIGUSR2, SignalCallback);

            /*
             * System.Threading.Thread signalThread = new System.Threading.Thread(delegate ()
             * {
             *      for (;;)
             *      {
             *              if (Engine.Instance.CancelRequested)
             *                      break;
             *
             *              int index = UnixSignal.WaitAny(m_signals, 1000);
             *
             *              if (index < m_signals.Length)
             *              {
             *                      Mono.Unix.Native.Signum signal = m_signals[index].Signum;
             *                      if (signal == Mono.Unix.Native.Signum.SIGTERM)
             *                              Engine.Instance.OnSignal("SIGTERM");
             *                      else if (signal == Mono.Unix.Native.Signum.SIGINT)
             *                              Engine.Instance.OnSignal("SIGINT");
             *                      else if (signal == Mono.Unix.Native.Signum.SIGUSR1)
             *                              Engine.Instance.OnSignal("SIGUSR1");
             *                      else if (signal == Mono.Unix.Native.Signum.SIGUSR2)
             *                              Engine.Instance.OnSignal("SIGUSR2");
             *              }
             *      }
             * });
             * signalThread.Start();
             */
        }
示例#8
0
        public override bool OnIpV6Do()
        {
            if (Engine.Instance.Storage.GetLower("ipv6.mode") == "disable")
            {
                string[] interfaces = GetInterfaces();
                foreach (string i in interfaces)
                {
                    string getInfo = SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-getinfo", SystemShell.EscapeInsideQuote(i) });

                    string mode    = Utils.RegExMatchOne(getInfo, "^IPv6: (.*?)$");
                    string address = Utils.RegExMatchOne(getInfo, "^IPv6 IP address: (.*?)$");

                    if ((mode == "") && (address != ""))
                    {
                        mode = "LinkLocal";
                    }

                    if (mode != "Off")
                    {
                        IpV6ModeEntry entry = new IpV6ModeEntry();
                        entry.Interface = i;
                        entry.Mode      = mode;
                        entry.Address   = address;
                        if (mode == "Manual")
                        {
                            entry.Router       = Utils.RegExMatchOne(getInfo, "^IPv6 IP Router: (.*?)$");
                            entry.PrefixLength = Utils.RegExMatchOne(getInfo, "^IPv6 Prefix Length: (.*?)$");
                        }
                        m_listIpV6Mode.Add(entry);

                        SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-setv6off", SystemShell.EscapeInsideQuote(i) });

                        Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.NetworkAdapterIpV6Disabled, i));
                    }
                }

                Recovery.Save();
            }

            base.OnIpV6Do();

            return(true);
        }
示例#9
0
        public string[] GetInterfaces()
        {
            List <string> result = new List <string>();

            foreach (string line in SystemShell.Shell("/usr/sbin/networksetup", new string[] { "-listallnetworkservices" }).Split('\n'))
            {
                if (line.StartsWith("An asterisk", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                if (line.Trim() == "")
                {
                    continue;
                }
                result.Add(line.Trim());
            }

            return(result.ToArray());
        }
示例#10
0
        public override IpAddresses DetectDNS()
        {
            IpAddresses list = new IpAddresses();

            string networksetupPath = LocateExecutable("networksetup");

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

                    string current = SystemShell.Shell(networksetupPath, new string[] { "-getdnsservers", SystemShell.EscapeInsideQuote(i2) });

                    list.Add(current);
                }
            }

            return(list);
        }