Example #1
0
        /// <summary>
        /// Deletes a user on the pritunl server
        /// </summary>
        /// <param name="organization">the organization to delete the user from</param>
        /// <param name="name">the name of the user to delete</param>
        /// <returns>A bool on whether the user was deleted or not</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 <bool> DeleteUser(string organization, string name)
        {
            var org = await Organizations.GetOrganization(organization);

            var user = await GetUserAsync(organization, name);

            return(await PritunlRequest.DeleteAsync <bool>($"user/{org.Id}/{user.Id}"));
        }
Example #2
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);
            }
        }
Example #3
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());
        }
Example #4
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>
 /// <summary>
 /// Gets a list of the organizations on the pritunl server
 /// </summary>
 /// <returns>List of Organizations</returns>
 public static async Task <List <Organization> > GetOrganizations()
 {
     return(await PritunlRequest.GetAsync <List <Organization> >("organization"));
 }
 /// <summary>
 /// Gets the servers on the pritunl server
 /// </summary>
 /// <returns>The list of servers</returns>
 public static async Task <List <Server> > GetServersAsync()
 {
     return(await PritunlRequest.GetAsync <List <Server> >("server"));
 }