Пример #1
0
        /// <summary>
        /// Gets an archive of the users openvpn configs
        /// </summary>
        /// <param name="organization">the organization to fetch configs from</param>
        /// <param name="name">the name of the user to fetch configs from</param>
        /// <param name="type">the archive type the config should be in</param>
        /// <returns>A byte array of the config data</returns>
        /// <exception cref="PritunlException"></exception>
        /// <remarks>Throws a <see cref="PritunlException"/> if it could't find the organization or the user</remarks>
        public static async Task <byte[]> GetKeys(string organization, string name, KeyType type)
        {
            var org = await Organizations.GetOrganization(organization);

            var user = await GetUserAsync(organization, name);

            var key = await PritunlRequest.GetAsync <Key>($"key/{org.Id}/{user.Id}");

            switch (type)
            {
            case KeyType.Tar:
                return(await PritunlRequest.GetAsync <byte[]>(key.KeyUrl));

            case KeyType.Zip:
                return(await PritunlRequest.GetAsync <byte[]>(key.KeyZipUrl));

            case KeyType.Onc:
                return(await PritunlRequest.GetAsync <byte[]>(key.KeyOncUrl));

            default:
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a user on the pritunl server
        /// </summary>
        /// <param name="organization">the organization to create the user in</param>
        /// <param name="name">the name of the user to create </param>
        /// <param name="email">the email of the user to create</param>
        /// <param name="disabled">whether the user will disabled on creation</param>
        /// <returns>The created user</returns>
        /// <exception cref="PritunlException"></exception>
        /// <remarks>Throws a <see cref="PritunlException"/> if it could't find the organization</remarks>
        public static async Task <User> CreateUser(string organization, string name, string email = null, bool disabled = false)
        {
            var org = await Organizations.GetOrganization(organization);

            return((await PritunlRequest.PostAsync <List <User> >($"user/{org.Id}", new { name, email, disabled })).First());
        }
Пример #3
0
        /// <summary>
        /// Gets a list of users from the organization
        /// </summary>
        /// <param name="organization">The organization to fetch users from</param>
        /// <returns>List of users in the org</returns>
        /// <exception cref="PritunlException"></exception>
        /// <remarks>Throws a <see cref="PritunlException"/> if it could't find the organization</remarks>
        public static async Task <List <User> > GetUsersAsync(string organization)
        {
            var org = await Organizations.GetOrganization(organization);

            return(await PritunlRequest.GetAsync <List <User> >($"user/{org.Id}"));
        }/// <summary>