Пример #1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="virtualServer">Owner virtual server.</param>
 /// <param name="owner">Owner UserCollection collection that owns this user.</param>
 /// <param name="id">User ID.</param>
 /// <param name="enabled">Specifies if user is enabled.</param>
 /// <param name="userName">User login name.</param>
 /// <param name="password">User password.</param>
 /// <param name="fullName">User full name.</param>
 /// <param name="description">User description.</param>
 /// <param name="mailboxSize">Mailbox size in MB.</param>
 /// <param name="permissions">Specifies user permissions.</param>
 /// <param name="creationTime">Time when user was created.</param>
 internal User(VirtualServer virtualServer, UserCollection owner, string id, bool enabled, string userName, string password, string fullName, string description, int mailboxSize, UserPermissions_enum permissions, DateTime creationTime)
 {
     m_pVirtualServer = virtualServer;
     m_pOwner         = owner;
     m_UserID         = id;
     m_Enabled        = enabled;
     m_UserName       = userName;
     m_Password       = password;
     m_FullName       = fullName;
     m_Description    = description;
     m_MailboxSize    = mailboxSize;
     m_Permissions    = permissions;
     m_CreationTime   = creationTime;
 }
Пример #2
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="virtualServer">Owner virtual server.</param>
 /// <param name="owner">Owner UserCollection collection that owns this user.</param>
 /// <param name="id">User ID.</param>
 /// <param name="enabled">Specifies if user is enabled.</param>
 /// <param name="userName">User login name.</param>
 /// <param name="password">User password.</param>
 /// <param name="fullName">User full name.</param>
 /// <param name="description">User description.</param>
 /// <param name="mailboxSize">Mailbox size in MB.</param>
 /// <param name="permissions">Specifies user permissions.</param>
 /// <param name="creationTime">Time when user was created.</param>
 internal User(VirtualServer virtualServer,UserCollection owner,string id,bool enabled,string userName,string password,string fullName,string description,int mailboxSize,UserPermissions_enum permissions,DateTime creationTime)
 {
     m_pVirtualServer  = virtualServer;
     m_pOwner          = owner;
     m_UserID          = id;
     m_Enabled         = enabled;
     m_UserName        = userName;
     m_Password        = password;
     m_FullName        = fullName;
     m_Description     = description;
     m_MailboxSize     = mailboxSize;
     m_Permissions     = permissions;
     m_CreationTime    = creationTime;
 }
Пример #3
0
        /// <summary>
		/// Adds new user to virtual server.
		/// </summary>
		/// <param name="userName">User login name.</param>
		/// <param name="fullName">User full name.</param> 
		/// <param name="password">User login password.</param>
		/// <param name="description">User description.</param>
		/// <param name="mailboxSize">Maximum mailbox size in MB.</param>
		/// <param name="enabled">Sepcifies if user is enabled.</param>
		/// <param name="permissions">Specifies user permissions.</param>
        public User Add(string userName,string fullName,string password,string description,int mailboxSize,bool enabled,UserPermissions_enum permissions)
        {
            /* AddUser <virtualServerID> "<userID>" "<userName>" "<fullName>" "<password>" "<description>" <mailboxSize> <enabled> <permissions>
                  Responses:
                    +OK                     
                    -ERR <errorText>
            */

            string id = Guid.NewGuid().ToString();
            
            // Call TCP AddUser
            m_pVirtualServer.Server.TcpClient.TcpStream.WriteLine("AddUser " + 
                m_pVirtualServer.VirtualServerID + " " + 
                TextUtils.QuoteString(id) + " " + 
                TextUtils.QuoteString(userName) + " " + 
                TextUtils.QuoteString(fullName) + " " + 
                TextUtils.QuoteString(password) + " " + 
                TextUtils.QuoteString(description) + " " + 
                mailboxSize + " " +
                enabled + " " +
                (int)permissions
            );
                        
            string response = m_pVirtualServer.Server.ReadLine();
            if(!response.ToUpper().StartsWith("+OK")){
                throw new Exception(response);
            }

            User user = new User(m_pVirtualServer,this,id,enabled,userName,password,fullName,description,mailboxSize,permissions,DateTime.Now);
            m_pUsers.Add(user);
            return user;
        }
        /// <summary>
        /// Adds new user to specified domain.
        /// </summary>
        /// <param name="userID">User ID. Suggested value is Guid.NewGuid() .</param>
        /// <param name="userName">User login name.</param>
        /// <param name="fullName">User full name.</param> 
        /// <param name="password">User login password.</param>
        /// <param name="description">User description.</param>
        /// <param name="domainName">Domain where to add user. Use <see cref="IMailServerApi.GetDomains">GetDomains()</see> to get valid values.</param>
        /// <param name="mailboxSize">Maximum mailbox size.</param>
        /// <param name="enabled">Sepcifies if user is enabled.</param>
        /// <param name="permissions">Specifies user permissions.</param>
        /// <remarks>Throws exception if specified user already exists.</remarks>
        public void AddUser(string userID,string userName,string fullName,string password,string description,string domainName,int mailboxSize,bool enabled,UserPermissions_enum permissions)
        {
            if(userID.Length == 0){
                throw new Exception("You must specify userID");
            }
            if(userName.Length == 0){
                throw new Exception("You must specify userName");
            }

            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddUser")){
                sqlCmd.AddParameter("_userID"      ,NpgsqlDbType.Varchar,userID);
                sqlCmd.AddParameter("_fullName"    ,NpgsqlDbType.Varchar,fullName);
                sqlCmd.AddParameter("_userName"    ,NpgsqlDbType.Varchar,userName);
                sqlCmd.AddParameter("_password"    ,NpgsqlDbType.Varchar,password);
                sqlCmd.AddParameter("_description" ,NpgsqlDbType.Varchar,description);
                sqlCmd.AddParameter("_domainName"  ,NpgsqlDbType.Varchar,domainName);
                sqlCmd.AddParameter("_mailboxSize" ,NpgsqlDbType.Integer,mailboxSize);
                sqlCmd.AddParameter("_enabled"     ,NpgsqlDbType.Boolean,enabled);
                sqlCmd.AddParameter("_permissions" ,NpgsqlDbType.Integer,permissions);

                DataSet ds = sqlCmd.Execute();
                ds.Tables[0].TableName = "Users";
            }
        }
Пример #5
0
 public void UpdateUser(string userID, string userName, string fullName, string password, string description, string domainName, int mailboxSize, bool enabled, UserPermissions_enum permissions)
 {
     if (userName.Length == 0)
     {
         throw new Exception("You must specify userName");
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         try
         {
             if (this.ContainsID(this.dsUsers.Tables["Users"], "UserID", userID))
             {
                 using (DataView dataView = new DataView(this.dsUsers.Tables["Users"]))
                 {
                     dataView.RowFilter = "UserID='" + userID + "'";
                     using (DataView dataView2 = new DataView(this.dsUsers.Tables["Users"]))
                     {
                         dataView2.RowFilter = "UserName='******'";
                         if (dataView2.Count > 0 && dataView2[0]["UserID"].ToString() != userID)
                         {
                             throw new Exception("User '" + userName + "' already exists !");
                         }
                     }
                     if (dataView.Count > 0)
                     {
                         if (dataView[0]["UserName"].ToString().ToLower() != userName.ToLower())
                         {
                             string text = API_Utlis.DirectoryExists(API_Utlis.PathFix(this.m_MailStorePath + "Mailboxes\\" + dataView[0]["UserName"]));
                             if (text != null)
                             {
                                 Directory.Move(text, API_Utlis.PathFix(this.m_MailStorePath + "Mailboxes\\" + userName));
                             }
                         }
                         dataView[0]["UserName"] = userName;
                         dataView[0]["FullName"] = fullName;
                         dataView[0]["Password"] = password;
                         dataView[0]["Description"] = description;
                         dataView[0]["DomainName"] = domainName;
                         dataView[0]["Mailbox_Size"] = mailboxSize;
                         dataView[0]["Enabled"] = enabled;
                         dataView[0]["Permissions"] = (int)permissions;
                         this.dsUsers.WriteXml(this.m_DataPath + "Users.xml", XmlWriteMode.IgnoreSchema);
                     }
                     goto IL_251;
                 }
                 goto IL_23B;
             IL_251:
                 goto IL_256;
             }
         IL_23B:
             throw new Exception("User with specified ID '" + userID + "' doesn't exist !");
         }
         catch (Exception ex)
         {
             throw ex;
         }
     IL_256: ;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
Пример #6
0
 public void AddUser(string userID, string userName, string fullName, string password, string description, string domainName, int mailboxSize, bool enabled, UserPermissions_enum permissions)
 {
     if (userID.Length == 0)
     {
         throw new Exception("You must specify userID");
     }
     if (userName.Length == 0)
     {
         throw new Exception("You must specify userName");
     }
     this.m_UpdSync.BeginUpdate();
     try
     {
         if (this.UserExists(userName))
         {
             throw new Exception("User '" + userName + "' already exists !");
         }
         if (this.ContainsID(this.dsUsers.Tables["Users"], "UserID", userID))
         {
             throw new Exception("User with specified ID '" + userID + "' already exists !");
         }
         DataRow dataRow = this.dsUsers.Tables["Users"].NewRow();
         dataRow["UserID"] = userID;
         dataRow["UserName"] = userName;
         dataRow["DomainName"] = domainName;
         dataRow["FullName"] = fullName;
         dataRow["Password"] = password;
         dataRow["Description"] = description;
         dataRow["Mailbox_Size"] = mailboxSize;
         dataRow["Enabled"] = enabled;
         dataRow["Permissions"] = (int)permissions;
         dataRow["CreationTime"] = DateTime.Now;
         this.dsUsers.Tables["Users"].Rows.Add(dataRow);
         this.dsUsers.WriteXml(this.m_DataPath + "Users.xml", XmlWriteMode.IgnoreSchema);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         this.m_UpdSync.EndUpdate();
     }
 }
Пример #7
0
		/// <summary>
		/// Updates new user to specified domain.
		/// </summary>
		/// <param name="userID">User id of the user which to update. Use <see cref="IMailServerApi.GetUsers">>GetUsers()</see> to get valid values.</param>
		/// <param name="userName">User login name.</param>
		/// <param name="fullName">User full name.</param>
		/// <param name="password">User login password.</param>
		/// <param name="description">User description.</param>
		/// <param name="domainName">Domain where to add user. Use <see cref="IMailServerApi.GetDomains">>GetDomains()</see> to get valid values.</param>
		/// <param name="mailboxSize">Maximum mailbox size.</param>
		/// <param name="enabled">Sepcifies if user is enabled.</param>
		/// <param name="permissions">Specifies user permissions.</param>
		public void UpdateUser(string userID,string userName,string fullName,string password,string description,string domainName,int mailboxSize,bool enabled,UserPermissions_enum permissions)
		{			
			if(userName.Length == 0){
				throw new Exception("You must specify userName");
			}

			m_UpdSync.BeginUpdate();

			try{
				if(ContainsID(dsUsers.Tables["Users"],"UserID",userID)){
					using(DataView dv = new DataView(dsUsers.Tables["Users"])){
						dv.RowFilter = "UserID='" + userID + "'";

						//--- see if user with specified user name doesn't exist by other user
						using(DataView dvX = new DataView(dsUsers.Tables["Users"])){
							dvX.RowFilter = "UserName='******'";

							if(dvX.Count > 0){
								// see if same user updated
								if(dvX[0]["UserID"].ToString() != userID){
									throw new Exception("User '" + userName + "' already exists !");
								}
							}
						}
                                                
						if(dv.Count > 0){
                            // Rename user mailbox folder
                            if(dv[0]["UserName"].ToString().ToLower() != userName.ToLower()){                                
                                string oldMailbox = API_Utlis.DirectoryExists(API_Utlis.PathFix(m_MailStorePath + "Mailboxes\\" + dv[0]["UserName"]));
                                if(oldMailbox != null){
                                    Directory.Move(oldMailbox,API_Utlis.PathFix(m_MailStorePath + "Mailboxes\\" + userName));
                                }
                            }

							dv[0]["UserName"]     = userName;
							dv[0]["FullName"]     = fullName;
							dv[0]["Password"]     = password;
							dv[0]["Description"]  = description;
							dv[0]["DomainName"]   = domainName;
							dv[0]["Mailbox_Size"] = mailboxSize;
							dv[0]["Enabled"]      = enabled;
							dv[0]["Permissions"]  = (int)permissions;

							dsUsers.WriteXml(m_DataPath + "Users.xml",XmlWriteMode.IgnoreSchema);
						}
					}
				}
				else{
					throw new Exception("User with specified ID '" + userID + "' doesn't exist !");
				}
			}
			catch(Exception x){
				throw x;
			}
			finally{
				m_UpdSync.EndUpdate();
			}
		}
        /// <summary>
        /// Adds new user to specified domain.
        /// </summary>
        /// <param name="userID">User ID. Suggested value is Guid.NewGuid() .</param>
        /// <param name="userName">User login name.</param>
        /// <param name="fullName">User full name.</param> 
        /// <param name="password">User login password.</param>
        /// <param name="description">User description.</param>
        /// <param name="domainName">Domain where to add user. Use <see cref="IMailServerApi.GetDomains">GetDomains()</see> to get valid values.</param>
        /// <param name="mailboxSize">Maximum mailbox size.</param>
        /// <param name="enabled">Sepcifies if user is enabled.</param>
        /// <param name="permissions">Specifies user permissions.</param>
        /// <remarks>Throws exception if specified user already exists.</remarks>
        public void AddUser(string userID,string userName,string fullName,string password,string description,string domainName,int mailboxSize,bool enabled,UserPermissions_enum permissions)
        {
            if(userID.Length == 0){
                throw new Exception("You must specify userID");
            }
            if(userName.Length == 0){
                throw new Exception("You must specify userName");
            }

            using(WSqlCommand sqlCmd = new WSqlCommand(m_ConStr,"lspr_AddUser")){
                sqlCmd.AddParameter("@UserID"      ,SqlDbType.NVarChar,userID);
                sqlCmd.AddParameter("@FullName"    ,SqlDbType.NVarChar,fullName);
                sqlCmd.AddParameter("@UserName"    ,SqlDbType.NVarChar,userName);
                sqlCmd.AddParameter("@Password"    ,SqlDbType.NVarChar,password);
                sqlCmd.AddParameter("@Description" ,SqlDbType.NVarChar,description);
                sqlCmd.AddParameter("@DomainName"  ,SqlDbType.NVarChar,domainName);
                sqlCmd.AddParameter("@MailboxSize" ,SqlDbType.NVarChar,mailboxSize);
                sqlCmd.AddParameter("@Enabled"     ,SqlDbType.Bit,enabled);
                sqlCmd.AddParameter("@permissions" ,SqlDbType.Int,permissions);

                DataSet ds = sqlCmd.Execute();
                ds.Tables[0].TableName = "Users";

                if(ds.Tables["Users"].Rows.Count > 0 && ds.Tables["Users"].Rows[0]["ErrorText"].ToString().Length > 0){
                    throw new Exception(ds.Tables["Users"].Rows[0]["ErrorText"].ToString());
                }
            }
        }