Пример #1
0
        /// <summary>
        /// Parses UserVpn structure from string
        /// </summary>
        /// <param name="user_vpn"></param>
        /// <param name="defaultVpn"></param>
        /// <returns></returns>
        public static UserVpn ParseUserVpn(string user_vpn, string defaultVpn)
        {
            UserVpn ret = new UserVpn(null, null);

            ret.vpn = defaultVpn;
            string[] splitstr = user_vpn.Split('@');
            ret.user = splitstr[0];
            if (splitstr.Length == 2)
            {
                ret.vpn = splitstr[1];
            }
            return(ret);
        }
Пример #2
0
        public bool Parse(string[] args, SessionConfiguration sc)
        {
            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-h":
                        i++;
                        sc.IpPort = IpPort.Parse(args[i]);
                        break;

                    case "-u":
                        i++;
                        sc.SetRouterUsername(UserVpn.Parse(args[i]));
                        break;

                    case "-w":
                        i++;
                        sc.SetUserPassword(args[i]);
                        break;

                    case "-z":
                        sc.Compression = true;
                        break;

                    case "-t":
                        i++;
                        string dm = args[i].ToLower();
                        MessageDeliveryMode?dmobj = ParseDeliveryMode(dm);
                        if (dmobj != null)
                        {
                            sc.DeliveryMode = dmobj.Value;
                        }
                        else
                        {
                            return(false);                                // err
                        }
                        break;

                    case "-l":
                        i++;
                        setLogLevel(args[i]);
                        break;

                    case "--durable":
                        sc.UseDurableEndpoint = true;
                        break;

                    case "-help":
                        return(false);    // err: print help

                    default:
                        string str_key   = args[i];
                        string str_value = "";
                        if (i + 1 < args.Length)
                        {
                            string str_tmpvalue = args[i + 1];                                 // lookahead
                            if (!str_tmpvalue.StartsWith("-"))
                            {
                                // we have a value!
                                i++;
                                str_value = args[i];
                            }
                        }
                        sc.ArgBag.Add(str_key, str_value);
                        break;
                    }
                }
            }
            catch (Exception)
            {
                return(false);                // err
            }

            bool clientCertUsed = false;

            if (sc.ArgBag.ContainsKey("-a"))
            {
                if (sc.ArgBag["-a"].Equals("CLIENT_CERTIFICATE"))
                {
                    clientCertUsed = true;
                }
            }

            if (sc.IpPort == null)
            {
                return(false);                // err
            }

            if (!clientCertUsed)
            {
                //Required when client certificates aren't used.
                if (sc.RouterUserVpn == null)
                {
                    return(false);
                }

                //Required when client certificates aren't used.
                if (sc.RouterUserVpn.user.Length == 0)
                {
                    return(false);
                }
            }

            // Disable certificate validation for all samples (Except secureSession which
            // will set this value from its own argument parser).
            sc.validateCertificate = false;

            return(true);            // success
        }
Пример #3
0
 public SessionConfiguration SetRouterUsername(UserVpn routerUserVpn)
 {
     this.routerUserVpn = routerUserVpn;
     return(this);
 }