コード例 #1
0
 public float GetFloat(string name)
 {
     return(Conversions.ToFloat(Get(name)));
 }
コード例 #2
0
 public Int64 GetInt64(string name)
 {
     return(Conversions.ToInt64(Get(name)));
 }
コード例 #3
0
 public int GetInt(string name)
 {
     return(Conversions.ToInt32(Get(name)));
 }
コード例 #4
0
 public bool GetBool(string name)
 {
     return(Conversions.ToBool(Get(name)));
 }
コード例 #5
0
        /*
         * public string Value
         * {
         *      get
         *      {
         *              return m_Value;
         *      }
         *      set
         *      {
         *              m_Value = value;
         *      }
         * }
         */

        public void Parse(string value)
        {
            m_ip      = null;
            m_bitmask = -1;

            value = value.Trim().Replace(" ", "/");

            string ip   = "";
            string mask = "";
            int    posS = value.IndexOf('/');

            if (posS == -1)
            {
                ip   = value.Trim();
                mask = "";
            }
            else
            {
                ip   = value.Substring(0, posS).Trim();
                mask = value.Substring(posS + 1).Trim();
            }

            if (System.Net.IPAddress.TryParse(ip.ToLowerInvariant().Trim(), out m_ip) == false)
            {
                m_ip = null;
            }

            // Only IPv4 or IPv6 address
            if (m_ip != null)
            {
                if ((m_ip.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork) &&
                    (m_ip.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6))
                {
                    m_ip = null;
                }
            }

            // Parse Mask
            if (m_ip != null)
            {
                if (mask == "")
                {
                    if (m_ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        m_bitmask = 32;
                    }
                    else if (m_ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                    {
                        m_bitmask = 128;
                    }
                }
                else
                {
                    int iMask = Conversions.ToInt32(mask);
                    if (iMask.ToString() == mask)
                    {
                        m_bitmask = iMask;
                    }
                    else if (m_ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)                    // IPv4 only
                    {
                        iMask = NetMask2bitMaskV4(mask);
                        if (iMask != -1)
                        {
                            m_bitmask = iMask;
                        }
                    }
                }
            }

            if (m_bitmask == -1)
            {
                m_ip      = null;
                m_bitmask = -1;
            }
        }
コード例 #6
0
ファイル: OpenVpnProcess.cs プロジェクト: martin762/Eddie
        public void Start()
        {
            m_command = new ElevatedProcess.Command();

            if (Platform.Instance.NeedExecuteOutsideAppPath(ExePath))
            {
                string tempPathToDelete = UtilsCore.GetTempPath() + "/openvpn-" + RandomGenerator.GetHash();
                if (Platform.Instance.FileExists(tempPathToDelete))
                {
                    Platform.Instance.FileDelete(tempPathToDelete);
                }
                System.IO.File.Copy(ExePath, tempPathToDelete);

                ExePath = tempPathToDelete;

                DeleteAfterStart = true;
            }

            m_command.Parameters["command"]     = "process_openvpn";
            m_command.Parameters["path"]        = ExePath;
            m_command.Parameters["airbuild"]    = (AirBuild ? "y":"n");
            m_command.Parameters["gui-version"] = Constants.Name + Constants.VersionDesc;
            m_command.Parameters["config"]      = ConfigPath;

            m_command.ExceptionEvent += delegate(ElevatedProcess.Command cmd, string message)
            {
                StdErr.Write("Error: " + message);
            };

            m_command.ReceiveEvent += delegate(ElevatedProcess.Command cmd, string data)
            {
                string feedbackType = data.Substring(0, 6);
                string feedbackData = data.Substring(7);

                if (feedbackType == "stdout")
                {
                    StdOut.Write(feedbackData);
                }
                else if (feedbackType == "stderr")
                {
                    StdErr.Write(feedbackData);
                }
                else if (feedbackType == "procid")
                {
                    m_pid = Conversions.ToInt32(feedbackData);
                    if (DeleteAfterStart)
                    {
                        Platform.Instance.FileDelete(ExePath);
                    }
                }
                else if (feedbackType == "return")
                {
                }
            };

            m_command.CompleteEvent += delegate(ElevatedProcess.Command cmd)
            {
                StdOut.Stop();
                StdErr.Stop();
                if (EndEvent != null)
                {
                    EndEvent();
                }
            };
            m_command.DoASync();
        }
コード例 #7
0
        protected void ReceiveData(string data)
        {
            m_bufferReceive += data;

            for (; ;)
            {
                int posEndLine = m_bufferReceive.IndexOf('\n');
                if (posEndLine == -1)
                {
                    break;
                }
                else
                {
                    string line = m_bufferReceive.Substring(0, posEndLine);
                    m_bufferReceive = m_bufferReceive.Substring(posEndLine + 1);

                    if (line.StartsWith("ee:", StringComparison.InvariantCulture) == false)
                    {
                        Engine.Instance.Logs.LogVerbose("Elevated unexpected log: " + line);
                    }
                    else
                    {
                        int posEndKind = line.IndexOf(':', 3);
                        if (posEndKind == -1)
                        {
                            return;
                        }
                        string packetKind = line.Substring(3, posEndKind - 3);

                        if (packetKind == "log")
                        {
                            string logB = line.Substring(posEndKind + 1);
                            string log  = Conversions.Base64ToString(logB);
                            Engine.Instance.Logs.LogVerbose(log); // For example, DNS flush messages
                        }
                        else if (packetKind == "fatal")
                        {
                            string logB = line.Substring(posEndKind + 1);
                            string log  = Conversions.Base64ToString(logB);
                            FatalError(log);
                        }
                        else if (packetKind == "pid")
                        {
                            // For example under MacOS, it's not possible to obtain PID with AuthorizationExecuteWithPrivileges.
                            // So, it's the elevated that inform the launcher of his PID.
                            string pidB = line.Substring(posEndKind + 1);
                            string pidS = Conversions.Base64ToString(pidB);
                            int    pid  = Conversions.ToInt32(pidS);
                            m_process = System.Diagnostics.Process.GetProcessById(pid);
                        }
                        else
                        {
                            int    posEndId   = line.IndexOf(":", posEndKind + 1, StringComparison.InvariantCulture);
                            string packetIdS  = "";
                            string packetData = "";
                            if (posEndId == -1)
                            {
                                packetIdS  = line.Substring(posEndKind + 1);
                                packetData = "";
                            }
                            else
                            {
                                packetIdS  = line.Substring(posEndKind + 1, posEndId - posEndKind - 1);
                                packetData = line.Substring(posEndId + 1);
                                packetData = Conversions.Base64ToString(packetData);
                            }

                            UInt32 packetId = Convert.ToUInt32(packetIdS);

                            if (PendingCommands.ContainsKey(packetId) == false)
                            {
                                return;
                            }

                            Command c = PendingCommands[packetId];
                            if (packetKind == "data")
                            {
                                c.Data(packetData);
                            }
                            else if (packetKind == "exception")
                            {
                                c.Exception(packetData);
                                PendingCommands.Remove(packetId);
                            }
                            else if (packetKind == "end")
                            {
                                c.End();
                                PendingCommands.Remove(packetId);
                            }
                        }
                    }
                }
            }
        }