コード例 #1
0
        public override void OnReport(Report report)
        {
            base.OnReport(report);

            report.Add("ifconfig", (LocateExecutable("ifconfig") != "") ? SystemShell.Shell0(LocateExecutable("ifconfig")) : "'ifconfig' " + Messages.NotFound);
            report.Add("netstat /rnl", (LocateExecutable("netstat") != "") ? SystemShell.Shell1(LocateExecutable("netstat"), "/rnl") : "'netstat' " + Messages.NotFound);
        }
コード例 #2
0
ファイル: Platform.cs プロジェクト: siemantic/Eddie
        public override void OnInit(bool cli)
        {
            base.OnInit(cli);

            m_version      = SystemShell.Shell1(LocateExecutable("uname"), "-a");
            m_architecture = NormalizeArchitecture(SystemShell.Shell1(LocateExecutable("uname"), "-m").Trim());
            m_uid          = 9999;
            UInt32.TryParse(SystemShell.Shell1(LocateExecutable("id"), "-u"), out m_uid);

            // Debian, Environment.UserName == 'root', $SUDO_USER == '', $LOGNAME == 'root', whoami == 'root', logname == 'myuser'
            // Ubuntu, Environment.UserName == 'root', $SUDO_USER == 'myuser', $LOGNAME == 'root', whoami == 'root', logname == 'no login name'
            // Manjaro, same as Ubuntu
            m_logname = Environment.GetEnvironmentVariable("SUDO_USER");
            if (m_logname == null)
            {
                m_logname = "";
            }
            else
            {
                m_logname = m_logname.Trim();
            }
            if (m_logname == "")
            {
                m_logname = SystemShell.Shell0(LocateExecutable("logname"));
            }
            if (m_logname.Contains("no login name"))
            {
                m_logname = Environment.UserName;
            }
            if (m_logname == null)
            {
                m_logname = "";
            }

            m_fontSystem = "";
            string gsettingsPath = LocateExecutable("gsettings");             // gnome

            if (gsettingsPath != "")
            {
                m_fontSystem = SystemShell.Shell1(gsettingsPath, "get org.gnome.desktop.interface font-name").Trim('\'');
                int posSize = m_fontSystem.LastIndexOf(" ");
                if (posSize != -1)
                {
                    m_fontSystem = m_fontSystem.Substring(0, posSize) + "," + m_fontSystem.Substring(posSize + 1);
                }
            }

            m_fontMonoSpace = "";
            if (gsettingsPath != "")
            {
                m_fontMonoSpace = SystemShell.Shell1(gsettingsPath, "get org.gnome.desktop.interface monospace-font-name").Trim('\'');
                int posSize = m_fontMonoSpace.LastIndexOf(" ");
                if (posSize != -1)
                {
                    m_fontMonoSpace = m_fontMonoSpace.Substring(0, posSize) + "," + m_fontMonoSpace.Substring(posSize + 1);
                }
            }

            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);
        }
コード例 #3
0
ファイル: Platform.cs プロジェクト: DreamAuth/Eddie
        public override void OnReport(Report report)
        {
            base.OnReport(report);

            report.Add("ifconfig", (LocateExecutable("ifconfig") != "") ? SystemShell.Shell0(LocateExecutable("ifconfig")) : "'ifconfig' " + LanguageManager.GetText("NotFound"));
        }
コード例 #4
0
        public override int StartProcessAsRoot(string path, string[] arguments, bool consoleMode)
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();

            bool canRunAsRoot = FileRunAsRoot(path);

            process = new System.Diagnostics.Process();
            if (canRunAsRoot)
            {
                process.StartInfo.FileName  = path;
                process.StartInfo.Arguments = String.Join(" ", arguments);
            }
            else
            {
                if (consoleMode)
                {
                    if (IsAdmin())
                    {
                        process.StartInfo.FileName  = path;
                        process.StartInfo.Arguments = String.Join(" ", arguments);
                    }
                    else
                    {
                        string sudoPath = LocateExecutable("sudo");
                        if (sudoPath != "")
                        {
                            List <string> groups = new List <string>(SystemShell.Shell0(LocateExecutable("groups")).ToLowerInv().Split(' '));
                            if (groups.Contains("sudo"))
                            {
                                process.StartInfo.FileName  = "sudo";
                                process.StartInfo.Arguments = "\"" + path + "\" " + String.Join(" ", arguments);
                            }
                            else
                            {
                                // Ask for password, but for unknown reason, password mismatch (endofline at first character), stdin issue, probably related to Mono.
                                //process.StartInfo.FileName = "su";
                                //process.StartInfo.Arguments = "-c \"'" + path + "' " + String.Join(" ", arguments) + "\"";
                            }
                        }
                    }
                }
                else
                {
                    process.StartInfo.FileName  = "pkexec";
                    process.StartInfo.Arguments = "\"" + path + "\" " + String.Join(" ", arguments);
                }
            }

            if (process.StartInfo.FileName == "")
            {
                Engine.Instance.Logs.LogFatal("Unable to find a method to run elevated process. Install 'sudo' and ensure user is in sudo group, or run chown root:root eddie-cli-elevated;chmod u+s eddie-cli-elevated");
                return(0);
            }
            else
            {
                process.StartInfo.WorkingDirectory = "";

                process.StartInfo.Verb            = "run";
                process.StartInfo.CreateNoWindow  = true;
                process.StartInfo.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                process.StartInfo.UseShellExecute = false;

                process.Start();

                return(process.Id);
            }
        }