private void SaveUser()
        {
            HtaccessUser user = new HtaccessUser();
            user.Name = usernameControl.Text;
            user.Password = passwordControl.Password;
            user.AuthType = rblAuthType.SelectedItem.Value;
            user.EncType  = rblEncType.SelectedItem.Value;
            user.Realm = tbDigestRealm.Text;

            List<string> groups = new List<string>();
            foreach (ListItem li in dlGroups.Items)
                if (li.Selected)
                    groups.Add(li.Value);

            user.Groups = groups.ToArray();

            try
            {
                int result = ES.Services.WebServers.UpdateHeliconApeUser(PanelRequest.ItemID, user);
                if (result < 0)
                {
                    ShowResultMessage(result);
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage("WEB_UPDATE_HeliconApe_USER", ex);
                return;
            }

        }
 /// <remarks/>
 public void UpdateHeliconApeUserAsync(int siteItemId, HtaccessUser user)
 {
     this.UpdateHeliconApeUserAsync(siteItemId, user, null);
 }
 /// <remarks/>
 public void UpdateHeliconApeUserAsync(int siteItemId, HtaccessUser user, object userState)
 {
     if ((this.UpdateHeliconApeUserOperationCompleted == null))
     {
         this.UpdateHeliconApeUserOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateHeliconApeUserOperationCompleted);
     }
     this.InvokeAsync("UpdateHeliconApeUser", new object[] {
                 siteItemId,
                 user}, this.UpdateHeliconApeUserOperationCompleted, userState);
 }
 public int UpdateHeliconApeUser(int siteItemId, HtaccessUser user)
 {
     object[] results = this.Invoke("UpdateHeliconApeUser", new object[] {
                 siteItemId,
                 user});
     return ((int)(results[0]));
 }
 /// <remarks/>
 public System.IAsyncResult BeginUpdateHeliconApeUser(int siteItemId, HtaccessUser user, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("UpdateHeliconApeUser", new object[] {
                 siteItemId,
                 user}, callback, asyncState);
 }
示例#6
0
 /// <remarks/>
 public void UpdateHeliconApeUserAsync(string siteId, HtaccessUser user) {
     this.UpdateHeliconApeUserAsync(siteId, user, null);
 }
示例#7
0
 public void UpdateHeliconApeUser(string siteId, HtaccessUser user)
 {
     try
     {
         Log.WriteStart("'{0}' UpdateHeliconApeUser", ProviderSettings.ProviderName);
         WebProvider.UpdateHeliconApeUser(siteId, user);
         Log.WriteEnd("'{0}' UpdateHeliconApeUser", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' UpdateHeliconApeUser", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
        public static int UpdateHeliconApeUser(int siteItemId, HtaccessUser user)
        {
            // load site item
            WebSite siteItem = (WebSite)PackageController.GetPackageItem(siteItemId);
            if (siteItem == null)
                return BusinessErrorCodes.ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND;

            // place log record
            TaskManager.StartTask("WEB_SITE", "UPDATE_HELICON_APE_USER", siteItem.Name, siteItemId);

            TaskManager.WriteParameter("User", user.Name);

            try
            {
                // update user
                WebServer web = GetWebServer(siteItem.ServiceId);
                web.UpdateHeliconApeUser(siteItem.SiteId, user);

                return 0;
            }
            catch (Exception ex)
            {
                throw TaskManager.WriteError(ex);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }
示例#9
0
 public void UpdateHeliconApeUser(string siteId, HtaccessUser user) {
     this.Invoke("UpdateHeliconApeUser", new object[] {
                 siteId,
                 user});
 }
示例#10
0
        private void UpdateHeliconApeUser(string siteId, HtaccessUser user, bool deleteUser)
        {
            if (HtaccessFolder.VALID_USER == user.Name)
                return;

            string rootPath = GetSiteContentPath(siteId);
            string usersPath = Path.Combine(rootPath, HtaccessFolder.HTPASSWDS_FILE);

            // load users file
            List<string> lines = HtaccessFolder.ReadLinesFile(usersPath);

            // check if the user already exists
            List<string> updatedLines = new List<string>();
            bool exists = false;
            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];
                string updatedLine = line;

                int colonIdx = line.IndexOf(":");
                if (colonIdx != -1)
                {
                    string username = line.Substring(0, colonIdx);
                    string password = line.Substring(colonIdx + 1);
                    if (String.Compare(username, user.Name, true) == 0)
                    {
                        // already exists
                        exists = true;

                        // check if we need to delete this user
                        if (deleteUser)
                            continue;

                        // change password if required
                        if (!String.IsNullOrEmpty(user.Password))
                        {
                            // hash password
                            password = GeneratePasswordHash(user);

                            // update line
                            updatedLine = username + ":" + password;
                        }
                    }
                }

                updatedLines.Add(updatedLine);
            }

            if (!exists && !deleteUser)
            {
                // new user has been added
                updatedLines.Add(user.Name + ":" + GeneratePasswordHash(user));
            }

            // save users file
            HtaccessFolder.WriteLinesFile(usersPath, updatedLines);

            if (user.Groups == null)
                user.Groups = new string[] { };

            // update groups
            // open groups file
            string groupsPath = Path.Combine(rootPath, HtaccessFolder.HTGROUPS_FILE);
            List<string> groupLines = HtaccessFolder.ReadLinesFile(groupsPath);

            for (int i = 0; i < groupLines.Count; i++)
            {
                string groupLine = groupLines[i];
                int colonIdx = groupLine.IndexOf(":");
                if (colonIdx != -1)
                {
                    string groupName = groupLine.Substring(0, colonIdx);
                    string[] groupMembers = groupLine.Substring(colonIdx + 1).Split(' ');

                    // check if user is assigned to this group
                    bool assigned = false;
                    for (int j = 0; j < user.Groups.Length; j++)
                    {
                        if (String.Compare(user.Groups[j], groupName, true) == 0)
                        {
                            assigned = true;
                            break;
                        }
                    }

                    // remove current user
                    List<string> updatedMembers = new List<string>();
                    for (int j = 0; j < groupMembers.Length; j++)
                    {
                        // user exists in the members
                        // check if he should be really added to this group
                        if (String.Compare(groupMembers[j], user.Name, true) == 0)
                            continue;

                        updatedMembers.Add(groupMembers[j]);
                    }

                    if (assigned)
                        updatedMembers.Add(user.Name);

                    // modify group line
                    groupLines[i] = groupName + ":" + String.Join(" ", updatedMembers.ToArray());
                }
            } // end iterating groups

            // save group file
            HtaccessFolder.WriteLinesFile(groupsPath, groupLines);
        }
示例#11
0
        public override void DeleteHeliconApeUser(string siteId, string userName)
        {
            string rootPath = GetSiteContentPath(siteId);
            HtaccessUser user = new HtaccessUser();
            user.Name = userName;

            // update users and groups
            UpdateHeliconApeUser(siteId, user, true);

            // update foleds
            //DeleteNonexistentUsersAndGroups(rootPath);
        }
示例#12
0
        public static string GeneratePasswordHash(HtaccessUser user)
        {
            if (HtaccessFolder.AUTH_TYPE_BASIC == user.AuthType)
            {

                // BASIC
                switch (user.EncType)
                {
                    case HtaccessUser.ENCODING_TYPE_APACHE_MD5:
                        return PasswdHelper.MD5Encode(user.Password, PasswdHelper.GetRandomSalt());
                    case HtaccessUser.ENCODING_TYPE_SHA1:
                        return PasswdHelper.SHA1Encode(user.Password);
                    case HtaccessUser.ENCODING_TYPE_UNIX_CRYPT:
                    default:
                        BsdDES bsdDes = new BsdDES();
                        return  bsdDes.Crypt(user.Password);
                }
            }

            // DIGEST
            return string.Format("{0}:{1}", user.Realm, PasswdHelper.DigestEncode(user.Name, user.Password, user.Realm));
        }
示例#13
0
 public override void UpdateHeliconApeUser(string siteId, HtaccessUser user)
 {
     UpdateHeliconApeUser(siteId, user, false);
 }
示例#14
0
        public override HtaccessUser GetHeliconApeUser(string siteId, string userName)
        {
            // load users file
            string rootPath = GetSiteContentPath(siteId);
            string usersPath = Path.Combine(rootPath, HtaccessFolder.HTPASSWDS_FILE);
            List<string> lines = HtaccessFolder.ReadLinesFile(usersPath);

            // iterate through all lines
            HtaccessUser user = null;
            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];

                int colonIdx = line.IndexOf(":");
                if (colonIdx != -1)
                {
                    string username = line.Substring(0, colonIdx);
                    string password = line.Substring(colonIdx + 1);
                    if (String.Compare(username, userName, true) == 0)
                    {
                        // exists
                        user = new HtaccessUser();
                        user.Name = username;
                        user.Password = password;
                        break;
                    }
                }
            }

            if (user == null)
                return null; // user doesn't exist

            List<string> userGroups = new List<string>();

            // read groups information
            // open groups file
            string groupsPath = Path.Combine(rootPath, HtaccessFolder.HTGROUPS_FILE);
            List<string> groupLines = HtaccessFolder.ReadLinesFile(groupsPath);

            for (int i = 0; i < groupLines.Count; i++)
            {
                string groupLine = groupLines[i];
                int colonIdx = groupLine.IndexOf(":");
                if (colonIdx != -1)
                {
                    string groupName = groupLine.Substring(0, colonIdx);
                    string[] groupMembers = groupLine.Substring(colonIdx + 1).Split(' ');

                    // check group members
                    for (int j = 0; j < groupMembers.Length; j++)
                    {
                        if (String.Compare(groupMembers[j], user.Name, true) == 0)
                        {
                            userGroups.Add(groupName);
                            break;
                        }
                    }
                }
            } // end iterating groups
            user.Groups = userGroups.ToArray();

            return user;
        }
 public int UpdateHeliconApeUser(int siteItemId, HtaccessUser user)
 {
     return WebServerController.UpdateHeliconApeUser(siteItemId, user);
 }
示例#16
0
		public void UpdateHeliconApeUser(string siteId, HtaccessUser user)
		{
			throw new NotImplementedException();
		}